Jump to content
Sign in to follow this  
fasad

creating a string from a variable name

Recommended Posts

Hey, I've melted my brain again...

I'm making a script that accepts a variable refering to a group. eg, in players init, eastGroup1 = group this

[eastGroup1] exec "script.sqs"

I want to use the text "eastGroup1" as a string, but i can't figure out how to retrieve it without it pointing directly to the group.

_string = _this select 0

gives "EAST Alpha Black"

_string = "_this select 0"

gives "_this select 0"

_string = format["%1",_this select 0]

gives "EAST Alpha Black"

Any idea how to get this working? I guess the script is not ever given the actual variable name. Could it work the other way? Ie, the arguement is a string, which needs to be reduced to the variable name?

For those who are curious, I need to keep track of a group that will be spawned and culled multiple times. The actual groupID (EAST Alpha Black) will be different every time.

Share this post


Link to post
Share on other sites

hmm solved it, backwards. I'm still interested in any thoughts or ideas on either approach.

instead of passing the variable, pass it as a string

["eastGroup1"] exec "script.sqs"

this in the script, the string can be turned into a variable name:

_groupName = _this select 0

_command = format["_temp = %1",_groupName]

_command foreach [0]

_groupID = _temp

_groupName is "eastGroup1"

_groupID is eastGroup1 which obviously points to EAST Alpha Black

Solution found Here

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  

×