Jump to content
Sign in to follow this  
zooloo75

Is it possible to have dynamically named variables?

Recommended Posts

I'm wondering if it is possible to have a variable be named dynamically - and if it's possible, then how is it done?

I'm thinking of something like

1_health

2_health

3_health

n_health

Just a continuation, and have it based off of each player or object.

Share this post


Link to post
Share on other sites

missionNamespace setVariable [format ["variable%1", _x], _value];

Share this post


Link to post
Share on other sites

how does one refer to a dynamic variable after generating it like this if part of the name was generated from a loop i.e.

_locations = nearestlocations [[0,0,0],["Airport","NameCityCapital","NameCity","NameVillage","NameLocal"],50000];

{
    _locname = name _x;
    _trgname = format ["%1_trigger",_locname];

    missionnamespace setvariable [_trgname,createTrigger ["emptyDetector",getpos _x]];

} foreach _locations;

how would i then go and set the statements for the triggers using settriggerstatements??

Edited by zorilya

Share this post


Link to post
Share on other sites

What is this supposed to do?

missionnamespace [_trgname,createTrigger ["emptyDetector",getpos _x]];

Share this post


Link to post
Share on other sites
What is this supposed to do?

missionnamespace [_trgname,createTrigger ["emptyDetector",getpos _x]];

sorry typo

fixed now

---------- Post added at 13:30 ---------- Previous post was at 13:10 ----------

best i can come up with is to use

(call compile _trgname) settriggerstatements ["this","hint 'trigger is on'","hint 'trigger is off'"];

is there a better way to do it?

Share this post


Link to post
Share on other sites
is there a better way to do it?

_trigger = missionNamespace getVariable _trgname;
_trigger setTriggerStatements ["this","hint 'trigger is on'","hint 'trigger is off'"];

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  

×