Jump to content
Sign in to follow this  
thecoolsideofthepillow

What to Do With a Variable That Sometimes Isn't Yet Defined?

Recommended Posts

I have a variable to keep track of a player who should be holding a certain item. The item is not always in the possession of a player, though, so the variable in question may be undefined. It doesn't stop it from working when it needs to, but the RPT error every time the onPlayerDeath script runs and the variable isn't defined makes debugging other things a bit annoying with the debug output of the non-critical error on screen.

 

I put a waitUntil {!isNull MyVariable} at the start of it, but it still continues with the script regardless, thus throwing up the undefined variable error, for some reason (and in line 3, not line 1 to indicate that the waitUntil command is giving the error).

 

Entire onPlayerKilled.sqf:

 

//This event script handles dropping the Encryption Key and changing the appropriate tasks

waitUntil {!isNull KeyCarrier}; //Still says undefined variable on init when units are set to spawn on start. Annoying, but does not affect functionality
_Corpse = _this select 0;
_CorpsePos = getpos _Corpse;
if (_Corpse == KeyCarrier) then 
{
	_EncKey = "Land_Laptop_device_F" createVehicle _CorpsePos;
	_EncKey addAction ["Take Encryption Key Locker", "EncryptionKey.sqf"];
	"KeyMarker" setMarkerPos getPos _EncKey;
	if (side _Corpse == west) then
	{
		tsk7b = ["Bring Key BLU", "FAILED", true] spawn BIS_fnc_taskSetState;
		tsk7r = ["Kill Carrier RED", "SUCCEEDED", true] spawn BIS_fnc_taskSetState;
	};
	if (side _Corpse == east) then
	{
		tsk7r = ["Bring Key RED", "FAILED", true] spawn BIS_fnc_taskSetState;
		tsk7r = ["Kill Carrier RED", "SUCCEEDED", true] spawn BIS_fnc_taskSetState;
	};
	tsk2b = ["Get Key BLU", "ASSIGNED", true] spawn BIS_fnc_taskSetState;
	tsk2r = ["Get Key RED", "ASSIGNED", true] spawn BIS_fnc_taskSetState;
	KeyCarrier = nil;
};

Any input on the task stuff would help too; that's what I'm actually working on now and it's a PITA.

Share this post


Link to post
Share on other sites

Define the variable before you evaluate state.

KeyCarrier = objNull;

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×