Jump to content
Sign in to follow this  
leysard

Problem with while {} do {}

Recommended Posts

Hello,

I wanted to write a script for making red/green zones without having to take hundreds of lines. My idea was to give coordinates in an array and then select these coordinates as long as there are some to set the zones.

Obviously, it's not working and that where I would appreciate some help

_zones = [[20650,6850],[20750,6850],[20850,6850]]; // Define 3 zones to create

_zoneAmount = count _zones; //Count the number of zones
_zoneTodo=0;
while {_zoneTodo<_zoneAmount} do //creates zones as long as there are still zones to create
{
_MarkerZone = "_MarkerZone" + str(_zoneTodo);
_TriggerGreenZone ="_TriggerGreenZone" + str(_zoneTodo);
_TriggerRedZone ="_TriggerRedZone" + str(_zoneTodo);

_MarkerZone = createMarker ["_MarkerZone", [((_zones select _zoneTodo)select 0),((_zones select _zoneTodo)select 1)]];
_MarkerZone setMarkerShape "RECTANGLE";
_MarkerZone setMarkerSize [50,50];
_TriggerGreenZone =createTrigger ["EmptyDetector", [((_zones select _zoneTodo)select 0),((_zones select _zoneTodo)select 1)]];
_TriggerGreenZone setTriggerArea [50,50,0,true];
_TriggerGreenZone setTriggerActivation ["WEST SEIZED", "PRESENT", true];
_TriggerGreenZone setTriggerStatements ["this", "'_MarkerZone' setMarkercolor 'colorGreen';",""];
_TriggerRedZone =createTrigger ["EmptyDetector", [((_zones select _zoneTodo)select 0),((_zones select _zoneTodo)select 1)]];
_TriggerRedZone setTriggerArea [50,50,0,true];
_TriggerRedZone setTriggerActivation ["EAST SEIZED", "PRESENT", true];
_TriggerRedZone setTriggerStatements ["this", "'_MarkerZone' setMarkercolor 'colorRed';",""];
_zoneTodo = _zoneTodo + 1;
sleep 0.05;
}

Edited by Leysard
Script error

Share this post


Link to post
Share on other sites

What's up with the '+ select 0' on line:

_MarkerZone + select 0 = createMarker ["_MarkerZone", [((_zones select _zoneTodo)select 0),((_zones select _zoneTodo)select 1)]];

Share this post


Link to post
Share on other sites

OOps, that's a mistake I forgot to take out.

So even without that, the script does only creates 1 square. In my example, should produce 3.

(By the way, edited my initial post to take out the slect mistake.

Share this post


Link to post
Share on other sites

your mistake is in the array selects. line 11, 14 and 18

change the positioning in them to:

[((_zones select _zoneTodo)select _zoneTodo select 0),((_zones select _zoneTodo)select _zoneTodo select 1)]

you created all 3 markers on the same 1st spot.

greetings Na_Palm

mom....

---------- Post added at 13:59 ---------- Previous post was at 13:50 ----------

forget my last post! this should work

_zones = [[20650,6850],[20750,6850],[20850,6850]]; // Define 3 zones to create

_zoneAmount = count _zones; //Count the number of zones
_zoneTodo=0;
while {_zoneTodo<_zoneAmount} do //creates zones as long as there are still zones to create
{
_MarkerName = "_MarkerZone" + str(_zoneTodo);
_TriggerGreenZone ="_TriggerGreenZone" + str(_zoneTodo);
_TriggerRedZone ="_TriggerRedZone" + str(_zoneTodo);

_MarkerZone = createMarker [_MarkerName, [((_zones select _zoneTodo)select 0),((_zones select _zoneTodo)select 1)]];
_MarkerZone setMarkerShape "RECTANGLE";
_MarkerZone setMarkerSize [50,50];
_TriggerGreenZone =createTrigger ["EmptyDetector", [((_zones select _zoneTodo)select 0),((_zones select _zoneTodo)select 1)]];
_TriggerGreenZone setTriggerArea [50,50,0,true];
_TriggerGreenZone setTriggerActivation ["WEST SEIZED", "PRESENT", true];
_TriggerGreenZone setTriggerStatements ["this", format["'%1' setMarkercolor 'colorGreen';", _MarkerName],""];
_TriggerRedZone =createTrigger ["EmptyDetector", [((_zones select _zoneTodo)select 0),((_zones select _zoneTodo)select 1)]];
_TriggerRedZone setTriggerArea [50,50,0,true];
_TriggerRedZone setTriggerActivation ["EAST SEIZED", "PRESENT", true];
_TriggerRedZone setTriggerStatements ["this", format["'%1' setMarkercolor 'colorRed';", _MarkerName],""];
_zoneTodo = _zoneTodo + 1;
sleep 0.05;
} 

Share this post


Link to post
Share on other sites

You could use the for "_i" from ... to ... do structure.

But, it still won't work properly as the triggerStatements cannot accept any local variables passed to them (I think). You'll either need to pass global vars (which is problematic) or work out another way of doing it.

I can't think of anything at the moment because I'm at work and I can't think clearly with all the work stuff going on.

Anyway, try it and see how you get on.

At the very least, the for .. from .. to .. do structure should be a good way of doing it:

_zones = [[20650,6850],[20750,6850],[20850,6850]];

_zoneAmount = count _zones;

for "_i" from 1 to _zoneAmount do
{

    _zoneToDo = _zones select _i;

    // YOUR CODE HERE
};

Edited by Das Attorney

Share this post


Link to post
Share on other sites

Ok Na_Palm, your solution works

I would like to add the next condition before considering the Task as Succeded. Of course, I would like it to be also automated with the previous part of script.

waitUntil {(markerColor "_MarkerZone0" == "ColorGreen") and (markerColor "_MarkerZone1" == "ColorGreen") and (markerColor "_MarkerZone2" == "ColorGreen")};

Das Attorney, what would be the "problematic" with using global variables instead of local ones ?

Share this post


Link to post
Share on other sites

I thought that the global vars would need to be unique otherwise they would overwrite each other as the script loops round.

However, looks like I got it wrong there as you've got it working. I Prob shouldn't reply to these threads when I'm at work and not in front of my Arma computer. Anyway - glad it's working for you :)

Share this post


Link to post
Share on other sites

Anyway, thanks Das Attorney for taking the time to help.

I'm still awaiting second part of my question to finish the script. Maybe a kind of "for each" to use Inside of the waituntil ?

Share this post


Link to post
Share on other sites

if you put your waitUntil after the ending bracket of your other loop it looks good and halts the script there.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×