Help with 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with timer (
/showthread.php?tid=72846)
Help with timer -
dice7 - 11.04.2009
I am trying to make a cmd, which will change a cars color every second, but I always get some sort of errors

Here's the code:
Код:
public OnPlayerConnect(playerid)
{
new timer1;
timer1 = SetTimer("rainbow",500,true); // 209
}
Код:
new PlayerRainbow[MAX_PLAYERS] = 0;
stock rainbow(playerid)
{
new ab, ac;
ab=rand(127);
ac=rand(127);
if (PlayerRainbow[playerid] = 1)
{
ChangeVehicleColor( vehicleid, ab, ac);
}
}
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/rainbowoff", cmdtext, true, 10) == 0)
{
KillTimer(timer1); //249
PlayerRainbow[playerid] = 0;
}
if (strcmp("/rainbow", cmdtext, true, 10) == 0)
{
PlayerRainbow[playerid] = 1;
}
}//I know this part of the code is poor, I will fix so you can only activate it in a car
I get these errors:
Код:
C:\Documents and Settings\Tadej\Desktop\samp server\samp02Xserver.win32\gamemodes\monster.pwn(209) : warning 204: symbol is assigned a value that is never used: "timer1"
C:\Documents and Settings\Tadej\Desktop\samp server\samp02Xserver.win32\gamemodes\monster.pwn(249) : error 017: undefined symbol "timer1"
I am also a scripting beginner
Re: Help with timer -
dice7 - 11.04.2009
bump
Re: Help with timer -
Nubotron - 11.04.2009
You have create 'timer1' inside a function, so this variable can only be used in that function. It is called a local variable.
You have to create it outside function, at top of script, it is then called a global variable, then you can use in other functions.
SetTimer do not accept functions with arguments, you will use SetTimerEx.
Re: Help with timer -
ICECOLDKILLAK8 - 11.04.2009
Remove the
Then place it at the top of your script,
You should think about using SetTimerEx and an array though :O