Little Mathematic ^_^
#1

Hello everybody I have little problem.I set timer ex, for 1 second and it will repeat, but in callback I set one variable which always will be +1 when timer repeats so it`s should give numbers like 1,2,3,4,5,6,.... but problem that it give me numbers always 1,1,1,1,... why I don`t know.

pawn Код:
SetTimerEx("OnPlayerTryToCapture", 1000, 1, "i", playerid);

public OnPlayerTryToCapture(playerid)
{
    new timer;
    timer += 1;
    SendDebug(playerid, "Time: %d", timer);
    return 1;
}
Reply
#2

Just make the variable global.
Like:
PHP код:
SetTimerEx("OnPlayerTryToCapture"10001"i"playerid);
new 
timer;
public 
OnPlayerTryToCapture(playerid)
{
    
timer += 1;
    
SendDebug(playerid"Time: %d"timer);
    return 
1;

The reason behind this is because whenever the function finishes.. Simply, the variable is reset to zero.. So you need to make it global so its never reset unless explicitly.
Reply
#3

You create a new 'timer' int each time OnPlayerTryToCapture is called, no wonder it's always 1

// oops, too late
Reply
#4

Yeah it's because you are creating the variable "timer" each time the timer is called. Make it a global variable.


EDIT: You know what? Fuck both of you other guys that answered at nearly the same exact time I did... XD
Reply
#5

F***, I totally forget that, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)