Jump to content
Sign in to follow this  
Tom212

Issue with storing a variable on a client.

Recommended Posts

I'm having some trouble with some code I'm trying to write. This function starts with the object of a player '_oldUnit', the idea is that it will then continue to make a civilian spawn, then select that unit while storing the object of the old one.

 

When that civilian respawns I need to return the player into the unit it was at the beginning of the function. I plan to run a function to return the player to it's old unit from the MPRespawn event handler, but somehow I need to get the client to store the it's old unit locally so that it can use it as a parameter for the second function. This is important because multiple players may be running this function.

_oldUnit = _this;
	
	_group = createGroup civilian;
	"c_man_polo_1_f" createUnit [getMarkerPos "spy_hq_marker", _group, "newUnit = this; private ['_myOldUnit']"]; //Civilian is spawned.
	[newUnit, "selectPlayer", _oldUnit] call BIS_fnc_MP; //Player selects the new civilian.
	_newUnit = newUnit; //The new unit is stored.
	
	_oldUnit call addSpy; //Not important.
	
	_newUnit setVariable ["_oldUnit", _oldUnit, false]; //My attempt to store the functions _oldUnit variable on the client.
	_newUnit addMPEventHandler ["MPRespawn", {}]; //This will run a function with the parameters of it's current unit and that of the _oldUnit.

Any help would be appreciated, this current code doesn't work. When I test it and check the value of _myOldUnit on the client it's undefined.

Share this post


Link to post
Share on other sites
_newUnit setVariable ["oldUnit", _oldUnit, true];

from the wiki:

 

objectName setVariable [name, value, public]

Share this post


Link to post
Share on other sites

In this case I need it to remain local. I removed the _ from "oldObject" while testing and forgot to put it back.

Share this post


Link to post
Share on other sites

In this case I need it to remain local. I removed the _ from "oldObject" while testing and forgot to put it back.

 

The "_" in this case should not be there. Also, "_myOldUnit" isn't defined anywhere in your script, so I am not surprised that it's coming up as undefined. 

Share this post


Link to post
Share on other sites

Sorry, I sent this code after alot of experimentation with it so alot of the values are incorrect and different from when I started with it and should have reverted them all. That's why there's some weird errors, I'm pretty sure I've found another way to solve my problem now so don't worry, thanks anyways.

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  

×