Home   Help Search Login Register  

Author Topic: Unique variables in MP scripts  (Read 1396 times)

0 Members and 2 Guests are viewing this topic.

Rubble_Maker

  • Guest
Unique variables in MP scripts
« 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?

Rubble_Maker

  • Guest
Re:Unique variables in MP scripts
« Reply #1 on: 10 Mar 2003, 20:20:45 »
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 ;)

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:Unique variables in MP scripts
« Reply #2 on: 12 Mar 2003, 05:36:12 »
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....
Dinger/Cfit

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Unique variables in MP scripts
« Reply #3 on: 12 Mar 2003, 23:50:44 »
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)

Rubble_Maker

  • Guest
Re:Unique variables in MP scripts
« Reply #4 on: 26 Mar 2003, 15:48:37 »
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
;)