OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: Rubble_Maker on 10 Mar 2003, 20:18:25
-
In Dinger/Jestapo's COC mine addon I stumbled accross the following line of code:
publicvariable format ["CoCMine%1", _i]
this obviously registers unique public variables (probably one per mine, I dunno). The question is: How do I access such a variable? For example, to compare two values; then something like
?(_anyNumber>format ["CoCMine%1", _i]): ...
probably won't work. Any ideas?
-
I forgot to mention that of course I want this to be totally flexible. Any number of variables should work, and this code will eventually be used in a loop, so a simple
?(_anyNumber>"CoCMine1): ...
won't do the trick ;)
-
ahhh yes.
welcome to the world of metavariables.
in this particular case, the variables have the names: CoCMine0 - CoCMineN, where N = the number of mines -1. For example, if you have 52 mines, they will b erepresented (Temporarily, because the init routine destroys the variables) by:
CoCmine0
CoCMine1
CoCMine2
...
CoCMine51
Thanks to 1.85, we have the call function, which makes metavariables much easier.
all you need to do is:
myvariable = call format ["MetaVariableNo%1", variablenumber]
as an aside, over at the CoC, bn880 and I are working on a method to break arrays into rationally-ordered series of variables....
-
Ah ha! My, that's cunning Dinger... ;)
I've been looking for a way to accomplish that, but gave up (some people just don't have what it takes ;D)
-
Ok that works just fine. A lil prob remains though: How does a certain unit know which number is associated with it? I mean if I have a script that simulates a soldier's AI, how does the script/soldier know what number it must plug into the metavariables?
I *tried* the dirty down way of just turning the whole unit ID into a variable prefix, but the stupid OFP engine trashes the IDs with several blanks so the "call" routine no longer generates a valid command. It'd look like this
WEST ALPHA BLACK #1 BehaviourMode=4
Of course an array which associates each unit with the corresponding number would work, but isn't there an easier way?
Oh, yes I could make a function that eliminates all the whitespaces before generating the command... OMG so much work just to make a stupid vaiable
;)