Home   Help Search Login Register  

Author Topic: Variable name from a string  (Read 2336 times)

0 Members and 1 Guest are viewing this topic.

Offline Ext3rmin4tor

  • Members
  • *
Variable name from a string
« 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?
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Variable name from a string
« Reply #1 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.

"When 900 years YOU reach, look as good you will not!"

Offline Ext3rmin4tor

  • Members
  • *
Re: Variable name from a string
« Reply #2 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
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Gaia

  • Members
  • *
  • Bohemia Interactive Senior Game Designer
    • My personal webpage (only in Czech)
Re: Variable name from a string
« Reply #3 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];