OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Ext3rmin4tor on 31 May 2010, 13:58:07

Title: Variable name from a string
Post by: Ext3rmin4tor on 31 May 2010, 13:58:07
Is there a way to create a variable name from a string? For example let us suppose I have a variable counter and I want to create a variable name including the number of that counter, that is something like "variable3" if the counter value is 3, is that possible?
Title: Re: Variable name from a string
Post by: Wolfrug on 31 May 2010, 14:07:42
What you probably mean is that you've created a string, e.g. "variable3", and you want to turn that into a global variable that can hold the scalar value, e.g. variable3 = 3 (or anything else)? This you can do like this:

Quote
call compile format ["%1 = 3", "YourString"];

That will basically translate into

Quote
YourString = 3;

I only use this method however when I need to, for instance, dynamically create global variables that can be saved from mission to mission in a campaign. For everyday use, you really don't -need- to create new global variables every other minute, usually there's a perfectly good way around it. What exactly do you need this thing for, how does the script look etc? Give us some more info and we might be able to give you an alternative way of figuring stuff out :)

Wolfrug out.

Title: Re: Variable name from a string
Post by: Ext3rmin4tor on 01 Jun 2010, 11:03:42
Thnks a lot  :) . I was just curious if this could be done, it is true that one will use it rarely
Title: Re: Variable name from a string
Post by: Gaia on 01 Jun 2010, 12:37:18
call compile is not performance friendly, I suggest to use this instead:
Code: [Select]
missionnamespace setvariable ["YourString",3];