Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
blasturbator

creating public variables

Recommended Posts

would this work to make 8 things that have numbered names i.e. name1, name2, name3, etc and have a public variable for each also named name1, name2, name3, etc?

for "_i" from 0 to 8 step 1 do {

   call compile format ["_name = 'name%1'", _i];

   obj createVehicle [the createVehicle stuff];
   obj setVehicleVarName _name;
   obj call compile format ["%1=_This ; PublicVariable '%1'",_name];
};

Also is there any way to retrieve the name of a unit? like getVehicleVarName or some magic.

edit: found the answer to second question, still wondering if first would work.

Edited by Blasturbator

Share this post


Link to post
Share on other sites

I think you are taking the hard way

for "_i" from 1 to 8 step 1 do {

   call compile format["name%1 = 'classname' createvehicle stuff; publicVariable 'name%1';", _i];
}; 

Check for syntax errors, as I didn't get a chance to run it.

Share this post


Link to post
Share on other sites

Yeah i got this working hours ago, but thanks for replying. The hard way was necessary because i also needed to give the vehicle a varName for use as string storage so i could delete and recreate it in a function with the same name and public variable by calling on the varName to define both. Was a pain to get going but it works now :)

Share this post


Link to post
Share on other sites

This is an alternative option without having to call compile stuff

for "_i" from 0 to 8 step 1 do {
_name = format["name%1", _i];
_obj createVehicle [the createVehicle stuff];
_obj setVehicleVarName _name;
missionNamespace setVariable [_name, _obj, true];
};

The true in setVariable broadcasts the value without having to use PublicVariable.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×