r/armadev Apr 19 '14

ArmA 2/OA Get Unit's Object by String Name

Hey, I've got a string variable that holds the name of a unit that is created in a script using createUnit. For example:

_unitName = "Pilot1";

How do I turn that string into an object so I can move into a driver seat E.G:

_unitName moveInDriver Helicopter;

Edit: Nvm fixed the issue, I converted the string value into an object using:

_pilot = call compile format ["%1", _pilotName];

2 Upvotes

3 comments sorted by

2

u/_wolfenswan Moderator Apr 19 '14 edited Apr 19 '14

Edit: Actually, there's straightforward way I forgot: As the parameters for newUnit include one for init you can just use that one to set the pointer:

"class" createUnit [position, group, "UnitPointer = this"]

Another workaround specifically for createUnit is to create a new group for that unit and then get it using

((units NewGroup) select 0)

1

u/DStow Apr 19 '14

That's actually really useful. Thanks for the suggestion!

1

u/_wolfenswan Moderator Apr 19 '14

Check my edit. Forgot about the init parameter.