Home   Help Search Login Register  

Author Topic: Script call for boolean in array, check if true & make false  (Read 599 times)

0 Members and 1 Guest are viewing this topic.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
The basic system is a trigger that keeps relocating to various towns. At each town if the trigger condition is met, "G_Alert" boolean becomes true.
This boolean is part of a line that allows a script to be run.
The second part of that line is another boolean, which is specific to the location the trigger is at. It is this second boolean that i need to manipulate
The actual town that the trigger is at, then runs a script. However, on the triggers next pass at the town, if the triggered script is still running, then i dont want the trigger to call a second instance of it
So i am wanting to initate a boolean check to exit the script at its start, if an additional script is called

Following is a much more simplified version of what i need, but the basic concept is there

The red highlighted text are the specific boolean relevant lines

eg (INIT.SQS)
Quote
town_bools = [G1t1_alert,G1t2_alert,G2t1_alert,G2t2_alert]
{_x = false} forEach town_bools

G1_town1 = [G1t1_flag,G1t1_alert]
G1_town2 = [G1t2_flag,G1t2_alert]
G1 = [G1_town1,G1_town2]

G2_town1 = [G2t1_flag,G1t1_alert]
G2_town2 = [G2t2_flag,G1t2_alert]
G2 = [G2_town1,G2_town2]

Garrisons = [G1,G2]

Monitor.sqs
Quote
;;Setposses the west detected by east town trigger to cycle through all the towns in a garrision
?! (local server): exit

~ random 5
#START
_GNo = 0
_Gcount = count (Garrisons)
_TNo = 0
goto "G_Loop"

#G_Start
_GNo = _GNo + 1
#G_Loop
? (_GNo >= _Gcount): _GNo = 0; goto "Start"
_selectedG = (Garrisons select _GNo); goto "T_Loop"


#T_Start
_TNo = _TNo + 1
#T_Loop
_Tcount = count (_selectedG)
? (_TNo >= _Tcount): _TNo = 0; goto "G_Start"
_selectedT = (_selectedG select _TNo); goto "TOWNcheck"

#TOWNcheck
G_Alert = false
_selectedFlag = (_selectedT select 0)
_bool = (_selectedT select 1)
?(_bool): hint "Boolstate is true"; goto "T_Start"
_Flag = (getpos _selectedFlag)
T_Trigger setpos _flag
 "Triggermarker" setmarkerpos (getpos T_Trigger)
~ (2 + (random 2))

? (G_Alert) && !(_bool): hint "Boolstate is false"; _selectedT exec "myscript.sqs"
goto "T_Start"


Myscript.sqs
Quote
_bool = _this select 1
?(_bool): exit
_bool = true


;;;(Do other non relevant stuff)

~60
_bool = false
(_this select 1) = _bool

exit


Problem1

?(_bool): hint "Boolstate is true"; goto "T_Start"
? (G_Alert) && !(_bool): hint "Boolstate is false"; _selectedT exec "myscript.sqs"

neither of these lines run the hint message, which basically means that the variable _Bool isnt being seen as a boolean

How do i correctly do this??

Problem2
How do i make "Myscript.sqs" change the array boolean from false to true and vice versa

NB>> when the system is working, there may be multiple instances of "Myscript.sqs" running, but called by different towns, so the use of global variables may become messy


Thanks in advance
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Script call for boolean in array, check if true & make false
« Reply #1 on: 20 Mar 2004, 11:41:13 »
Well I'm not a scripting expert, so I may just be showing my ignorance .... however, it seems to me that

_selectedT = (_selectedG select _TNo)

that is to say, _selectedT is not an array.      Later, you have

_selectedT exec "myscript.sqs"

Shouldn't that be [_selectedT exec "myscript.sqs"]?   Can you pass a local variable like this?    Even if you can and it's being seen as an array doesn't _selectedT have only one element, and therefore _this select 1 performed on it is going to return null?

On the second point, I'd just use a global for each town:  it gets set to true when myscript first runs and myscript checks all the town variables before running again.    Not elegant, but simple and effective.
Plenty of reviewed ArmA missions for you to play

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Script call for boolean in array, check if true & make false
« Reply #2 on: 20 Mar 2004, 17:04:44 »
Suma said
Quote
In OFP scripting languague the only assignment possible is assingment to variable. There are no pointers (or nothing like l-value in C and C++).

Let me take two exception from you code which look like wrongly supposing something acts like l-value:

(_this select 1) = _bool

This is syntactically wrong. The only thing which can be on the left side of "=" is variable name. To change a value in an array you need to use set command line this _this set [1,_bool]

The code

Code: [Select]
town_bools = [G1t1_alert,G1t2_alert,G2t1_alert,G2t2_alert]
{_x = false} forEach town_bools

will not work as expected from the same reason. The town_bools array will be an array of values, which will be the results of evaluation of G1t1_alert... It makes no sense to assign to them. Moreover, assigning to _x in forEach will do nothing from the very same reason - _x is not l-value. To get something like pointer or l-value you could use a code like this:

Code: [Select]
town_bools = [ "G1t1_alert","G1t2_alert","G2t1_alert","G2t2_alert"]
{call (_x +"= false")} forEach town_bools


************************************************************
Well I'm not a scripting expert, so I may just be showing my ignorance .... however, it seems to me that

_selectedT = (_selectedG select _TNo)

that is to say, _selectedT is not an array.      Later, you have

_selectedT exec "myscript.sqs"

Shouldn't that be [_selectedT exec "myscript.sqs"]
Quote


if _Gno = 0
_selectedG is G1

G1 is an array containing the following sub-arrays
[G1_town1,G1_town2]

if _Tno = 0
_selectedT is G1_town1, (this contains two elements)

G1_town1 is an array containing an objects and a boolean

hope that explains it for you macguba
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123