Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
target_practice

Dynamically naming variables

Recommended Posts

Is it possible to alter the name of a variable using a different variable?

For instance, if I had a script that returned some data to a variable, what would I need to do so said variable's name could be suffixed by a string passed to the script?

Share this post


Link to post
Share on other sites
20 minutes ago, target_practice said:

Is it possible to alter the name of a variable using a different variable?

For instance, if I had a script that returned some data to a variable, what would I need to do so said variable's name could be suffixed by a string passed to the script?

 

You can't rename variables, only create new variables with a name depending on the input data, which doesn't make sense in any case I can think of.

Wouldn't it be better to use a variable holding a string and adjust the string depending on input data?

 

What are you trying to do?

 

Cheers

Share this post


Link to post
Share on other sites

I'd ideally want a script to declare a variable as true under a certain conidtion, with part of variable's name being determined by one of the arguments.

Share this post


Link to post
Share on other sites
1 minute ago, target_practice said:

I'd ideally want a script to declare a variable as true under a certain conidtion, with part of variable's name being determined by one of the arguments.

You can use the setVariable command to set a variable by a name.

 

myFunc = {
    params ["_varSuffix"];

    missionNamespace setVariable ["condition"+_varSuffix, true];
};

"_test" call myFunc; //Variable condition_test will be set to true.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

×