Problem with foreach? -
Tee - 26.06.2012
Suddenly my foreach include starts to act up...I ran a loop with 6 players online and it only executed the code for ID 0. What could wrong?
Re: Problem with foreach? -
ViniBorn - 26.06.2012
It called by any timer?
Can you show the code?
Re: Problem with foreach? -
Tee - 26.06.2012
Yea it's called by a timer. The loop is in a 2 millisecond timer (it's a part of my speedometer)
Re: Problem with foreach? -
ViniBorn - 26.06.2012
If you are using SetTimer, replace it with SetTimerEx
Re: Problem with foreach? -
Tee - 26.06.2012
Okay, I will but what's the problem? It has been working all along.
Re: Problem with foreach? -
ViniBorn - 26.06.2012
I'm sorry, I fumbled in my thinking.
Your speedometer is something like this?
pawn Код:
public Speedometer()
{
//
}
Or
pawn Код:
public Speedometer(playerid)
{
//
}
Re: Problem with foreach? -
Tee - 26.06.2012
I'm wondering if it's conflicting with Blue-G's MySQL R7 plugin, cause it was working fine when I was on R6, or it's just a co-incident.
Re: Problem with foreach? -
ReneG - 26.06.2012
Post the code wherever you use foreach
There can be quite a lot of things wrong, and it would be hard to find out without seeing the code.
Re: Problem with foreach? -
Tee - 26.06.2012
I only have the problem in the code snippet I PMed to you. Is it possible for a 1 millisecond timer to be faster than a loop through 6 players?
Re: Problem with foreach? -
ReneG - 26.06.2012
It really depends on what you're trying to do.
You're trying to make a speedometer so instead of using a timer, use the OnPlayerUpdate callback. It gets called around 30 times a sec, and it has a playerid parameter so you can avoid issues with foreach.
But if you actually need a timer use y_timers.
pawn Код:
task Timer[1000]()
{
foreach(Player, i)
{
// if the player is in a vehicle
if(IsPlayerInAnyVehicle(i))
{
// math code here
// textdraw code here
}
}
return 1;
}
With y_timers, you don't have to use SetTimer, you don't have to forward any timers. The number between the [ ] is the tick rate, put in how often in milliseconds you want the function to be called.