A Question About Timer
#1

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?
Reply
#2

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]++;
Reply
#3

Try t++
Reply
#4

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?
Reply
#5

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)