Jump to content
Sign in to follow this  
Desrat

Problem with condition for exitWith

Recommended Posts

Can't seem to get this right, creating a convoy to follow a route using Rube library, CBA and some functionality found posted by Rydygier all seems well except the BOLD RED section, it just doesn't fire when the convoy is destroyed which leaves me to believe it's some sort of scope issue but as the Variable is global I don't understand why it's not working (I should add the index comparison works fine i.e when all waypoints are complete it exits just fine, it's just the VOWS_CONVOY_DESTROYED that fails).

I'd appreciate if someone more versed in a2 scripting could quickly peruse this and (probably within seconds) highlight what I'm doing wrong... Thanks in advance..

// ENSURE FUNCTIONS MODULE LOADED
waituntil {!(isnil "bis_fnc_init")}; 


// START OF FUNCTIONS FOR START END POSITIONS // 
// GET TOWN LOCATIONS
_towns = nearestLocations [getPosATL player, ["NameVillage","NameCity","NameCityCapital"], 100000];


// PICK START LOCATION
_pos1 = position (_towns select (floor (random (count _towns))));
_RandomTownPosition1 = [_pos1 select 0,_pos1 select 1,0];


// FIND THE ROAD SEGMENTS WITHIN THE CIRCLE OF GIVEN RADIUS AND ENSURE START POINT IS ON ROAD
_nRoads = _RandomTownPosition1 nearRoads 10;
_rng = 10;
while {((count _nRoads) == 0)} do
   {
   _rng = _rng * 2;
   _nRoads = _RandomTownPosition1 nearRoads _rng;
   };
_RandomTownPosition1 = position (_nRoads select (floor (random (count _nRoads))));


// GET CONVOY END DESTINATION
_towns = nearestLocations [_RandomTownPosition1, ["NameVillage","NameCity","NameCityCapital"], 100000];
_RandomTownPosition2 = _RandomTownPosition1;


// PICK A DESTINATION AT LEAST 2.5KM AWAY
   {
   if (((position _x) distance _RandomTownPosition2) > 2500) exitwith  {_RandomTownPosition2 = [(position _x) select 0,(position _x) select 1,0]}
   }
foreach _towns;


// AGAIN ENSURE END POSITION IS ON A ROAD
_nRoads = _RandomTownPosition2 nearRoads 10;
_rng = 10;
while {((count _nRoads) == 0)} do
   {
   _rng = _rng * 2;
   _nRoads = _RandomTownPosition2 nearRoads _rng;
   };
_RandomTownPosition2 = position (_nRoads select (floor (random (count _nRoads))));
// END OF FUNCTIONS FOR START END POSITIONS // 


// START SPAWNING VEHICLES //
// SPAWN VEHICLE 1ST VEHICLE ALWAYS WHEELED
_v1 = [_RandomTownPosition1, 001, (VOWS_EAST_RU_VEH call BIS_fnc_selectRandom), east] call bis_fnc_spawnvehicle;


// MAKE LEADER NOT STUPID AND HIGH RANK
VOWS_CURRENT_GROUP = _v1 select 2;
_leader = leader VOWS_CURRENT_GROUP;
_leader setRank "COLONEL";
_leader setskill 1;


// RANDOM GROUP NUMBER = 3 + (0-3)
nToSpawn = (floor (random 3)) + 3;


// SPAWN VEHICLES IN LOOP FOR NTOSPAWN TIMES
for [{_i=0}, {_i<nToSpawn}, {_i=_i+1}] do
{
   sleep 1;
   // CHOOSE RANDOM VEHICLE FROM ARRAY
   _vcl = VOWS_EAST_RU_CONVOY call BIS_fnc_selectRandom;
   // FIND FREE SPACE TO SPAWN FOR VEHICLE FIRST WITHIN 100m
   _position = _RandomTownPosition1 findEmptyPosition[ 1 , 100 , _vcl];
   // SPAWN VEHICLE AND JOIN TO CURRENT GROUP
   [_position, 001, _vcl, VOWS_CURRENT_GROUP] call bis_fnc_spawnvehicle;
};


// ENSURE SPEED, COMBAT & FORMATION MATCH CONVOY NEEDS
VOWS_CURRENT_GROUP allowFleeing 0;
VOWS_CURRENT_GROUP setCombatMode "YELLOW";
VOWS_CURRENT_GROUP setFormation "COLUMN";
VOWS_CURRENT_GROUP setSpeedMode "LIMITED";




// FUNCTION TO GET ROUTE BETWEEN 2 POINTS
   _route = [
      ["start", _RandomTownPosition1],
      ["end", _RandomTownPosition2]
   ] call RUBE_findRoute;


// FUNCTION TO DRAW ROUTE ON MAP    
   // plot route (see RUBE_plotRoute)
   _markers = [_route,[["id", ([] call RUBE_createID)],["color", "ColorBlue"]]] call RUBE_plotRoute;


// DECLARE VARIABLES TO CHECK ALONG ROUTE
VOWS_CONVOY_COMPLETE = false;
VOWS_WAYPOINT_COMPLETE = false;
VOWS_CONVOY_DESTROYED = false;


// SELECT THE WAYPOINT ARRAY FROM ROUTE FUNCTION
_wpArray = _route select 2;


// DELETE DEFAULT WAYPOINT FROM GROUP
deleteWaypoint [VOWS_CURRENT_GROUP, 0];


// ADD 1ST WAYPOINT
VOWS_WAYPOINT = [VOWS_CURRENT_GROUP, (_wpArray select 0), 5, "MOVE", "SAFE", "YELLOW", "NORMAL", "COLUMN", "VOWS_WAYPOINT_COMPLETE = true", [3,6,9]] call CBA_fnc_addWaypoint;
"wpMark" setMarkerPos (_wpArray select 0);


// DECLARE SOME VARIABLES FOR WHILE LOOP
VOWS_TOTAL_INDEX = count _wpArray;
VOWS_CURRENT_INDEX = 0;


// SPAWN THREAD TO CHECK FOR DESTROYED
[] spawn 
{
   while {true} do
   {
       sleep 60;
       if (({alive _x} count units VOWS_CURRENT_GROUP) < 1) exitWith {VOWS_CONVOY_DESTROYED;VOWS_WAYPOINT_COMPLETE;};
   };
};


// START WHILE LOOP
while {true} do 
{
   // CHECK FOR REMAINING RESULTS IN ARRAY
   [font=arial black][color=#ff0000]if ((VOWS_TOTAL_INDEX == VOWS_CURRENT_INDEX) or (VOWS_CONVOY_DESTROYED)) exitWith [/color]
[color=#ff0000]    {[/color]
[color=#ff0000]    // NO MORE WAYPOINTS AVAILABLE SO EXIT[/color]
[color=#ff0000]    VOWS_WAYPOINT_COMPLETE;[/color]
[color=#ff0000]    hint "exiting loop";[/color]
[color=#ff0000]    };[/color][/font]

   // WAIT TILL CURRENT WAYPOINT COMPLETE
   waituntil {VOWS_WAYPOINT_COMPLETE};

   // RESET COMPLETE VARIABLE
   VOWS_WAYPOINT_COMPLETE = false;

   // NEW WAYPOINT
   VOWS_WAYPOINT = [VOWS_CURRENT_GROUP, (_wpArray select VOWS_CURRENT_INDEX), 5, "MOVE", "SAFE", "YELLOW", "NORMAL", "COLUMN", "VOWS_WAYPOINT_COMPLETE = true", [3,6,9]] call CBA_fnc_addWaypoint;

   // MOVE WAYPOINT MARK
   "wpMark" setMarkerPos (_wpArray select VOWS_CURRENT_INDEX);

   // INCREMENT INDEX FOR LOOP
   VOWS_CURRENT_INDEX = VOWS_CURRENT_INDEX + 1;
};    
// END WHILE LOOP




VOWS_WAYPOINT = [VOWS_CURRENT_GROUP, (_wpArray select (VOWS_TOTAL_INDEX - 1)), 5, "MOVE", "SAFE", "YELLOW", "LIMITED", "COLUMN", "VOWS_CONVOY_COMPLETE = true", [3,6,9]] call CBA_fnc_addWaypoint;


   // wait till current waypoint complete
   waituntil {(VOWS_CONVOY_COMPLETE) or (VOWS_CONVOY_DESTROYED)};
   hint "Convoy Completed";

Edited by Desrat
solved

Share this post


Link to post
Share on other sites

Where is VOWS_CONVOY_DESTROYED set to true? Sorry, i didn't read whole script.

---------- Post added at 13:34 ---------- Previous post was at 13:32 ----------

if (({alive _x} count units VOWS_CURRENT_GROUP) < 1) exitWith {VOWS_CONVOY_DESTROYED[color=#ff0000]=True[/color];VOWS_WAYPOINT_COMPLETE[color=#ff0000]=True[/color]};

Share this post


Link to post
Share on other sites

I'd read and re-read that line about 200 times at least and every time failed to notice I'd done that..sometimes just needs different eyes...thx

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  

×