Jump to content
Sign in to follow this  
eddyaod

vehicleVarName versus public object references

Recommended Posts

Hi all,

I recently discovered vehicleVarName's (only began playing around with Arma scripting 3 weeks ago) and I feel that they may help me with a few problems I've been facing, specifically regarding keeping track of objects whilst using the inbuilt respawn functionality. I'm thinking of reworking some of my code to use the vehiclevarnames. However, I'm not entirely thrilled about adding what is basically another layer of indirection unless there are no better (non-hacky) ways to handle situations where you've passed an object reference to an SQF and need to monitor the object beyond it dying and respawning. Has anyone got any good paradigms they stick to when handling this kind of thing?

As a further note, I'm also considering replacing the inbuilt respawn system with one that provides more flexibility but I'd like to make sure I'm getting the most out of the respawn system before needing to reinvent the wheel. Are vehicleVarNames still good in light of this? (I could handle passing of varnames to the respawned objects myself, but would that make an alternative system pretty much transparent to dependent code?)

tldr; Do you like vehicleVarNames (and why) or do you have a better system involving public object references?

Share this post


Link to post
Share on other sites

I hate everything multiplayer, it's a pain in the a.. to script. Single Player forever!!

(Yes, I've been having a nightmare getting some MP stuff to work... heh)

Share this post


Link to post
Share on other sites

I feel that no amount of dynamic or clever SP content will top playing games with + against other humans. The MP scripting situation is very tough though, but the coding's half the fun right?! :)

Share this post


Link to post
Share on other sites

But yes, I use the vehicleVarNames usually. Sometimes you can use markers too. Name it one thing, make it's text something else to keep track of things.

Share this post


Link to post
Share on other sites

I dont think it keeps the varname for vehicles, but I could be wrong. Anyway I prefer not using the default respawn system for vehicles. As you said, I prefer more flexibility.

Have a look at this respawn script if you want:

http://forums.bistudio.com/showthread.php?t=79070

Now about keeping track of respawning soldiers you could use this framework:

_temp = _this select 0;
_varname = vehicleVarName _temp;
_unit = objnull;

while {true} do {
waitUntil {
	call compile format ["_unit = %1",_varname];
	alive _unit;
};

while {alive _unit} do {
	// put your scripting here,
	// this block will loop as long as the unit is alive 
	// and after respawn it will start again.
};
sleep 5;
};  

It saves the varname on init and once the unit is no longer alive it will keep checking until the varname is assigned again (meaning that the unit has respawned). :o

Share this post


Link to post
Share on other sites

Thanks, I'll give that a try. My current epic failure is a map where a group of units has some addAction options both for themselves and when in vehicles.

First spawn everything works great, after the respawn however they lose both the addActions and the ability to get them in the vehicles (though it adds it to the vehicle sometimes, and even then it's available to everyone from OUTSIDE the silly thing...)

Triggers however tell me that the unit's name remains the same, just all the addAction stuff breaks totally.

Share this post


Link to post
Share on other sites
_temp = _this select 0;
_varname = vehicleVarName _temp;
_unit = objnull;

while {true} do {
waitUntil {
	call compile format ["_unit = %1",_varname];
	alive _unit;
};

while {alive _unit} do {
	// put your scripting here,
	// this block will loop as long as the unit is alive 
	// and after respawn it will start again.
};
sleep 5;
};  

This is quite a useful piece of code. I made a modification to accept any code as a parameter to execute in the while block.

_temp = _this select 0;
_code = _this select 1;
_varname = vehicleVarName _temp;
_unit = objnull;

while {true} do {
waitUntil {
	call compile format ["_unit = %1",_varname];
	alive _unit;
};

while {alive _unit} do {
	_unit call _code;
};
sleep 5;
};

You can use _this to reference the unit in the passed code.

Share this post


Link to post
Share on other sites

Thanks for the input guys.

From what I've tried, the best system I found is to use vehicle var names AND public object references, and I've changed my scripts to still take object references as parameters but check objects for varNames, and in the case that they have one, to operate on whatever object has the varName at any moment as opposed to sticking to just one object.

Haven't genericised the system in a way i'm happy with yet, as I prefer to avoid passing around large pieces of code as strings. Makes the bugs/errors even harder to find.

Share this post


Link to post
Share on other sites
Now about keeping track of respawning soldiers you could use this framework:

_temp = _this select 0;
_varname = vehicleVarName _temp;
_unit = objnull;

while {true} do {
waitUntil {
	call compile format ["_unit = %1",_varname];
	alive _unit;
};

while {alive _unit} do {
	// put your scripting here,
	// this block will loop as long as the unit is alive 
	// and after respawn it will start again.
};
sleep 5;
};  

It saves the varname on init and once the unit is no longer alive it will keep checking until the varname is assigned again (meaning that the unit has respawned). :o

Tajin, this looks like something I was thinking about using for a multiplayer mission. My idea is to have 4 AI units spawn onto each player. As those AI units die off, they respawn back onto the player after 45 seconds. If the player himself dies, then the AI wait until he has respawned before they respawn again.

Is the above example able to work like that? If so, how would I go about about getting that to work? Thank you!

Share this post


Link to post
Share on other sites

Could someone explain to me the difference between:

call compile format ["_unit = %1",_varname]; 

or

_unit = _varname; 

I would like to understand the content or state of the variable "unit" in certain conditions. For example lets take one unit from the array allunits:

sourceentry = allUnits;
oneunit = sourceentry select 0;
// What exactly is now the content of the variable oneunit, especially when ai?
// Lets further assume the unit has a name in the editor and the name shall be t1 (as variable in the in game editor). Does that influence the content of the variable oneunit? if so, how?

_varname = vehicleVarName oneunit;
//What is now the content of _varname?

call compile format ["_ccfvarname = %1",_varname];
//What will be the content of _ccfvarname here?

Which of these things will be changed after respawn, which name will adress the dead corpse, which names will adress the respawned alive unit?

Any help to get some insights is greatly appreciated.

Greetings,

Firebird

Edited by Firebird49th

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  

×