Help with timer
#1

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

bump
Reply
#3

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.
Reply
#4

Remove the
pawn Код:
new timer1;
Then place it at the top of your script,
You should think about using SetTimerEx and an array though :O
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)