Home   Help Search Login Register  

Author Topic: Random script for random attack  (Read 1120 times)

0 Members and 1 Guest are viewing this topic.

Offline White Angel

  • Members
  • *
  • White Angel
    • Armee Francaise Misison Developpement
Random script for random attack
« on: 21 Jul 2008, 18:49:03 »
I have written the following code to create random ennemy attack on a town.
This code is launched 5 times when a civil is walken (with waypoints) on 5 different triggers (which launch the following code).
Each execution of the code change one of the 5 variable to 1. In the game this change free an enemy group on its waypoint.



Code: [Select]
?!local server:x=floor(random 5)

publicvariable "x"

?(x) == 0: goto "val_0"
?(x) == 1: goto "val_1"
?(x) == 2: goto "val_2"
?(x) == 3: goto "val_3"
?(x) == 4: goto "val_4"

#val_0
? (zero_x) == 1 : goto "val_1"
zero_x=1
publicvariable "zero_x"
goto "fin"

#val_1
? (un_x) == 1 : goto "val_2"
un_x=1
publicvariable "un_x"
goto "fin"
#val_2

? (deux_x) == 1 : goto "val_3"
deux_x=1
publicvariable "deux_x"
goto "fin"
#val_3

? (trois_x) == 1 : goto "val_4"
trois_x=1
publicvariable "trois_x"
goto "fin"
#val_4

? (quatre_x) == 1 : goto "val_0"
quatre_x=1
publicvariable "quatre_x"

#fin

This code must be launch only 5 time. If it is launch more there is no exit !

initialization of variables are in the init file :


Code: [Select]
PublicVariable "_x";
PublicVariable "_zero_x";
PublicVariable "_un_x";
PublicVariable "_deux_x";
PublicVariable "_trois_x";
PublicVariable "_quatre_x";

_x = 0;
_zero_x = 0;
_un_x = 0;
_deux_x = 0;
_trois_x = 0;
_quatre_x = 0;



The problem i find is that variable : _zero_x, _un_x, ..., _quatre_x, never keep there state o or 1 for each launch of the code.

How can i do this ?
clic --> AFMoD (Armée Française MissiOns Développement)
clic --> R3F

"Don't tell people how to do things. Tell them what to do and let them surprise you with their results."   George S. Pat

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Random script for random attack
« Reply #1 on: 22 Jul 2008, 01:05:31 »
Variables that start with underscore are local to the script they are created in. You want to leave the underscore off and then you'd have a global variable which would be visible in all scripts throughout the mission.

LOCAL variables: _frog, _fish12, _pickled_eels_price
GLOBAL variables: cheeseAndOnions, SPON_whyArePeasGreen
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline White Angel

  • Members
  • *
  • White Angel
    • Armee Francaise Misison Developpement
Re: Random script for random attack
« Reply #2 on: 22 Jul 2008, 21:49:53 »
Thank's a lot Spooner, it works fine  ;)

How can i have forgotten this !!! :confused: :dunno: shame on me !
« Last Edit: 22 Jul 2008, 21:54:20 by White Angel »
clic --> AFMoD (Armée Française MissiOns Développement)
clic --> R3F

"Don't tell people how to do things. Tell them what to do and let them surprise you with their results."   George S. Pat