[HELP]Weird timer bug
#1

Hello,
Today i've tried to make a command with timers,/bomb.
Its suppose to make an explosion,after 1 second another one,etc.4 explosions.
Well here is the code:
On the top:
pawn Код:
forward ExTimer1(playerid);//The Ex=Explosion
forward ExTimer2(playerid);
forward ExTimer3(playerid);
forward ExTimer4(playerid);
OnPlayerCommandText:
pawn Код:
if (strcmp("/bomb", cmdtext, true, 10) == 0)
    {
    CreateExplosion(-1415.4913,490.6862,11.2429,7,100);
    SetTimerEx("ExTimer1",1000,0,"d",playerid);
    }
On the bottom:
pawn Код:
public ExTimer1(playerid)
{
    CreateExplosion(-1415.4913,490.6862,11.2429,7,100);
  SetTimerEx("ExTimer1",1000,0,"d",playerid);
    return 1;
}
public ExTimer2(playerid)
{
    CreateExplosion(-1417.1440,491.5547,11.5640,7,100);
  SetTimerEx("ExTimer2",1000,0,"d",playerid);
    return 1;
}
public ExTimer3(playerid)
{
    CreateExplosion(-1418.9178,491.6942,13.8101,7,100);
  SetTimerEx("ExTimer3",1000,0,"d",playerid);
    return 1;
}
public ExTimer4(playerid)
{
    CreateExplosion(-1421.4771,492.4316,11.1953,7,100);
  SetTimerEx("ExTimer4",1000,0,"d",playerid);
    return 1;
}
No errors at compiling.
Well,Whats the bug?

What happens is,that when im using /bomb,its starts,1 explosion,good,2 explosions,good,3 explosions,good,4 explosions,good,5 explosions,WTF?there supposed to be 4 explosions only.and it makes endless explosions at the same place.what am i doing wrong?

Excuse me,its the first time im using timers
Reply
#2

The /bomb command creates the first boom

Timer 1 the second

Timer 2 the third and so on

Edit: Also the endless explosions is couse each of the callbacks tells them to call the same function again which makes it loop



Код:
forward ExTimer1(playerid);//The Ex=Explosion
forward ExTimer2(playerid);
forward ExTimer3(playerid);
Код:
if (strcmp("/bomb", cmdtext, true, 10) == 0)
{
CreateExplosion(-1415.4913,490.6862,11.2429,7,100);
SetTimerEx("ExTimer1",1000,0,"d",playerid);
}
Код:
public ExTimer1(playerid)
{
CreateExplosion(-1415.4913,490.6862,11.2429,7,100);
  SetTimerEx("ExTimer2",1000,0,"d",playerid);
return 1;
}
public ExTimer2(playerid)
{
CreateExplosion(-1417.1440,491.5547,11.5640,7,100);
  SetTimerEx("ExTimer3",1000,0,"d",playerid);
return 1;
}
public ExTimer3(playerid)
{
CreateExplosion(-1418.9178,491.6942,13.8101,7,100);
return 1;
}
Reply
#3

Quote:
Originally Posted by Desert
The /bomb command creates the first boom

Timer 1 the second

Timer 2 the third and so on

Edit: Also the endless explosions is couse each of the callbacks tells them to call the same function again which makes it loop
Ok,Thanks
Reply
#4

If you look carefully your code, you can see that you never call ExTimer2, instead, in Extimer1, you run a timer that call ExTimer1 again, this is why it's endless and always at the same position.
Reply
#5

Quote:
Originally Posted by 0rb
If you look carefully your code, you can see that you never call ExTimer2, instead, in Extimer1, you run a timer that call ExTimer1 again, this is why it's endless and always at the same position.
Ow,i see 0.0
Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)