Jump to content
Sign in to follow this  
meatball

Creating Object Name based on variable?

Recommended Posts

Trying to create an object name by concatenating some text with a number that will increment based on a variable. So something like this:

_objectName = "text" + _numVariable;

I've tried to create a test object using createvehicle using this.

_objectName = "I_UAV_02_F" createvehicle (getmarkerPos "center");

Problem is, I can't use _objectName to createVehicle because _objectName now has quotes around it. I need to be able to watch for that vehicles destruction, so I'm not sure where to go next. Any ideas?

Share this post


Link to post
Share on other sites

Not very nice looking, but this should work:

call (compile (format['%1 = "I_UAV_02_F" createvehicle (getmarkerPos "center");', _objectName]));

Or just:

call (compile (format['%1 = %2;', _objectName, _vehicle]));

Or:

missionNamespace setVariable [_objectName, _vehicle];

missionNamespace

Edited by sxp2high
2 alternatives :)

Share this post


Link to post
Share on other sites

I'm confused.

Aside from the object name issue, I understand that you are creating a vehicle and want to watch for that vehicle's destruction, but how does the name factor into that?

For example, why wouldn't the following code work for you:

_objectName = "I_UAV_02_F" createvehicle (getmarkerPos "center");  
waitUntil {!(alive _objectName)};

(Highly simplified code based on what you said you're trying to do.)

Share this post


Link to post
Share on other sites

I'll test some of those, but I don't really have a problem actually creating the object, it's a matter of returning the actual objects name after creation so I can use it in other functions to watch for the destruction of the object.

Share this post


Link to post
Share on other sites

Something like....

{
//Create a vehicle
_Veh = createVehicle ["I_UAV_02_F", getMarkerPos "center", [], 0, "None"];

//Create a name 
_vehName = format[ "UAV_%1", str _x];
//Associate the vehicle with the name
_veh setVehicleVarName _vehName;
//Associate a global variable of name with the vehicle
missionNamespace set [_vehName, _veh];
//transmit global variable to all connect computers
publicVariable _vehName;

}forEach [1,2,3,4,5];

Would create 5 UAV's called UAV_1 to UAV_5 and also broadcasts the name if you need a reference to it on other machines.

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  

×