PDA

View Full Version : A Question About Timer


Cannary2048
27/07/2014, 09:54 PM
Hello, so I was messing around with the SetTimerEx function, while I create this CMD:

CMD:lol(playerid, params[])
{
testtimer[playerid] = SetTimerEx("EndTiming", 1000, true, "d", playerid);
}

the callback:

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?

Jefff
27/07/2014, 10:05 PM
Its always 1 because you are creating variable 't' every time per player and new t; means 0

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]++;

GeekSiMo
27/07/2014, 10:06 PM
Try t++

Cannary2048
27/07/2014, 10:10 PM
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?

Jefff
27/07/2014, 10:19 PM
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;
}