Jump to content
Sign in to follow this  
usbstuck

Dynamic getVariable in setWaypointStatements

Recommended Posts

I would like to access a variable with getVariable in setWaypointStatements. However, the variable name is dynamic, because I don't know how many variables there will be set.

 

Referring to this post I came up with the following:

params ["_group", "_pos", "_type", "_additionalStatements"];
private ["_wp", "_ref", "_refString"];

_wp = _group addWaypoint [_pos, 0];
_wp setWaypointType _type;

// Make sure chopper lands on the spot
_ref = "Land_HelipadCivil_F" createvehicle (_pos);

// Save reference to Helipad on group leader
_refString = "land_"+ str random [0, 5000, 10000];
_group setVariable [_refString, _ref, true];
hint format ["Reference to helipad: %1", _refString, _ref];

// Use reference on group leader to clean up Helipad after landing
call compile format ["_wp setWaypointStatements [""true"", ""deleteVehicle ((group this) getVariable '%1'); %2""]", _refString, _additionalStatements];

(_wp)

This works. But I have 2 objections:

1) It's not super-easy to read

2) Adding another format inside the statement (eg: `hint format ["%1", _someVar]` ) will break it.

 

Does anyone know a better way?

 

Thanks!

 

 

**Edit:

Actually objection #2 does work :rolleyes: . It was a different error I got...

So basically the only thing that remains of the question is if it can be done neater. But hey, maybe I should just get used to it ;)

Share this post


Link to post
Share on other sites

You already have the object of the helipad (from the return value of createVehicle saved to the local variable _ref), so no need to do all the strings and setVariables, just delete the object.

call compile format ["_wp setWaypointStatements [""true"", ""deleteVehicle '%1'); %2""]", _ref, _additionalStatements];

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  

×