OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started 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?
-
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:
call compile format ["%1 = 3", "YourString"];
That will basically translate into
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.
-
Thnks a lot :) . I was just curious if this could be done, it is true that one will use it rarely
-
call compile is not performance friendly, I suggest to use this instead:
missionnamespace setvariable ["YourString",3];