A Question About Timer - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: A Question About Timer (
/showthread.php?tid=528407)
A Question About Timer -
Cannary2048 - 27.07.2014
Hello, so I was messing around with the SetTimerEx function, while I create this CMD:
pawn Код:
CMD:lol(playerid, params[])
{
testtimer[playerid] = SetTimerEx("EndTiming", 1000, true, "d", playerid);
}
the callback:
pawn Код:
forward EndTiming();
public EndTiming()
{
for(new i=0; i < MAX_PLAYERS; i++)
{
new t;
new string[32];
t+=1;
format(string, sizeof(string), "t=%d", t);
SendClientMessage(i, -1, string);
}
}
while I'm testing the code in game, it ended up like
Код:
[04:58:36] t=1
[04:58:37] t=1
[04:58:38] t=1
[04:58:39] t=1
[04:58:40] t=1
[04:58:41] t=1
[04:58:42] t=1
[04:58:43] t=1
[04:58:44] t=1
[04:58:45] t=1
while it's supposed to increase one by one every one second, any explanations?
Re: A Question About Timer -
Jefff - 27.07.2014
Its always 1 because you are creating variable 't' every time per player and new t; means 0
pawn Код:
forward EndTiming(playerid);
public EndTiming(playerid)
{
static t;
new string[32];
t++;
format(string, sizeof(string), "t=%d", t);
SendClientMessage(playerid, -1, string);
}
but t should be for every player, on top new Time[MAX_PLAYERS]; then in public Time[playerid]++;
Re: A Question About Timer -
GeekSiMo - 27.07.2014
Try t++
Re: A Question About Timer -
Cannary2048 - 27.07.2014
Thanks but it's increasing by 500 not one
Код:
[05:32:03] t=1
[05:32:04] t=501
[05:32:05] t=1001
[05:32:06] t=1501
[05:32:07] t=2001
[05:32:08] t=2501
[05:32:09] t=3001
[05:32:10] t=3501
[05:32:11] t=4001
[05:32:12] t=4501
help?
Re: A Question About Timer -
Jefff - 27.07.2014
pawn Код:
new Time[MAX_PLAYERS];
forward EndTiming(playerid);
public EndTiming(playerid)
{
new string[32];
format(string, sizeof(string), "t=%d", ++Time[playerid]);
SendClientMessage(playerid, -1, string);
}
CMD:lol(playerid, params[])
{
Time[playerid] = 0;
KillTimer(testtimer[playerid]);
testtimer[playerid] = SetTimerEx("EndTiming", 1000, true, "d", playerid);
return 1;
}