Can't kill a timer
#1

When you exit a vehicle a timer is set off, when you enter the vehicle, the timer should be killed, but it doesn't get killed and it triggers a fuction when a player is driving the vehicle which shouldn't happen.

Код:
This is OnPlayerExitVehicle

	KillTimer(Timer_VehAlarm[vehicleid]);
	Timer_VehAlarm[vehicleid] = SetTimerEx("DisableVehicleLE", 1000*15, false, "d", vehicleid);
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	new Timer_VehAlarm[MAX_VEHICLES];
	KillTimer(Timer_VehAlarm[vehicleid]);
Reply
#2

This is because variables have a scope; put plainly, a life within a certain amount of code. In case you create it in a function, like here (OnPlayerEnter/ExitVehicle), the variable will be destroyed at the end of the function and anything assigned to it will be lost.

In order to have this variable carry a value over to another function, you will need to create it globally, outside of any other function. In case you are not sure on that position, try placing it above the main() function. You will also need to remove the code where you create it locally within the functions so the compiler doesn't throw a warning/error.
Reply
#3

Okay, I'm getting some of this, but how else do I make it work?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)