Jump to content
BlacKnightBK

waitUntil not working with multiple conditions

Recommended Posts

Hello guys,

I created a script where the CSAT is supposed to attack a location. The players are supposed to eliminate that counter attack. Once eliminated the mission is a success. It fails however once the AIs enter the city. I wrote the wait until as you will see below. my problem is when they enter the city. The mission ends pretty well once they are eliminated. But when they are in the city the Ais just keep patrolling and the mission never ends.

 

private ["_allUnits","_areTheyDead","_trigger"];
_allUnits = units _counterAttackers;

_trigger = createTrigger ["EmptyDetector", getMarkerPos MAINAOLOC];
_trigger setTriggerArea [400, 400, 0, false];
_trigger setTriggerActivation [_counterAttackers, "PRESENT", false];
_trigger setTriggerStatements ["this","",""];

waitUntil {

    sleep 1;
    _aliveUnits = _allUnits select {alive _x};
    _areTheyDead = (count _aliveUnits);

    (_areTheyDead < 5) or (triggerActivated _trigger)
};

//======================== Mission Ending

if (_areTheyDead < 5) then {
	sleep 10;

	private ["_textArray","_title","_text1","_text2","_text3","_text4"];
	_text1 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>HA HAAA, City Saved and counter attack repented, CSAT should just retire. Good job Boys. Now you can RTB";
	_text2 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>We got worried for a second their guys that you would not make it. Nice job again.";
	_text3 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>You happy? Well don't be, there is still more of those bastards on the island. RTB to resupply and get back out there.";
	_text4 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>Congratualtion boys, you saved the resistance and the city, report back to base and lets all pop one together before the next mission.";
	//*******
	_textArray = [_text1,_text2,_text3,_text4];
	_title = "<t color='#00ff00' size='2' shadow='1' shadowColor='#000000' align='center'>Counter Attack Eliminated</t>";

	_text = _textArray call BIS_fnc_selectRandom;
	hint parseText (_title + _text);

	[CA_Task, "Succeeded",true] spawn BIS_fnc_taskSetState;
}
else {

	sleep 10;
	private ["_textArray","_text","_title"];
	_text = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'> They managed to get into the city, i am sorry boys but there is nothing that can be done now. RTB. We lost this battle.";
	_title = "<t color='#00ff00' size='2' shadow='1' shadowColor='#000000' align='center'>Counter Attack Failed</t>";
	hint parseText (_title + _text);
	[CA_Task, "Failed",true] spawn BIS_fnc_taskSetState;

};

 

Share this post


Link to post
Share on other sites

_areTheyDead only exists inside the waitUntil scope and _counterAttackers is undefined, which will lead to _allUnits being undefined as well, at least from what you've posted.

Just define both before the waitUntil check.

 

Cheers

Share this post


Link to post
Share on other sites
1 minute ago, Grumpy Old Man said:

_areTheyDead only exists inside the waitUntil scope and _counterAttackers is undefined, which will lead to _allUnits being undefined as well, at least from what you've posted.

Just define both before the waitUntil check.

 

Cheers

 

 _counterAttackers has been defined earlier right at the top. it is the name I gave to the squad attacking

Also, why is "_allUnits" undefined. Line 2 I made it an array which contains all the units in the squad  "_counterAtackers".

As for "_areTheyDead" I declared it outside the waitUntil, shouldn't that cause it to keep its value until it has been niled or script ends??

Share this post


Link to post
Share on other sites

you have syntax error. _counterAttackers cannot be both a group and trigger activation type string. Check your .rpt

  • Like 1

Share this post


Link to post
Share on other sites
Just now, killzone_kid said:

you have syntax error. _counterAttackers cannot be both a group and trigger activation type string. Check your .rpt

hmm, in this case, i will have to switch it to east because I did not want other CSAT units to activate it.

 

Thanks

Share this post


Link to post
Share on other sites

I have no idea what you have to do as I have not a slightest clue what the value of _counterAttackers is. From incomplete presentation of a problem all I can say for sure you absolutely cannot use the same variable for both, units command and setTriggerActivation command.

Share this post


Link to post
Share on other sites
1 minute ago, killzone_kid said:

I have no idea what you have to do as I have not a slightest clue what the value of _counterAttackers is. From incomplete presentation of a problem all I can say for sure you absolutely cannot use the same variable for both, units command and setTriggerActivation command.

 

_counterAttackers has been defined as

_counterAttackers = creategroup east;

So like i told grumpy before, it is a group

Share this post


Link to post
Share on other sites
32 minutes ago, killzone_kid said:

If it is a group, why are you using it with setTriggerActivation?

I don't want every CSAT to be bale to activate it, just those ones in that squad.

52 minutes ago, Grumpy Old Man said:

Since you didn't post the entire script we can only guess.

No crystal ball here.

 

Cheers

 

The rest is working fine, all I did before is spawn the units and vehicles, assign them to their vehicles not much but it was a 200 line code so I didn't think you might want all of it. but sinc eyou do here it is.

/*-----------------------------------------------------------------
 File Name: cities_counter.sqf
 Created by: Y. Ibrahim
 Community: Arma Team Play
 TS: ateamplay.clants.nl
 Website: armasteamplay.com

 Use, distribution and editing of this file is authorized as long
 as the credits above are left untouched. However, if you would like
 to use multiple files wriiten by this author you are required to get
 author's permission.
-------------------------------------------------------------------*/

private ["_tempest1","_tempest2","_tempest3","_marid","_counterAttackers", "_spawnLoc", "_nullArray","_tigris"];
_nullArray = [];

//**************************************************************
	_title  = "<t color='#ff0000' size='2' shadow='1' shadowColor='#000000' align='center'>INCOMING COUNTER ATTACK</t>";
	_text   = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>All Units in Kavala, Hold up! Counter attack incoming, read your mission briefing.";
	hint parseText (_title + _text);

	CA_MissionBriefing = "CSAT ain't happy boys you stopped their search and kill mission, they have sent out a counter attack force, now we would have pulled you out along with the resistance in there but we are afraid they might not be coming just for you and the resistance but to take out all of the kavalaians in one go so they can prove a point. Hold of that counter attack boys at all costs, they do not get into kavala. The counter attack is coming all the way from their base, so you have time to plan out how you will stop them. If there is a CAS on standby we will direct it to take them out and save you the effort, if not, Good luck boys. Fate of Kavala depends on you.";

MAINAOLOC = "Kavala";

//***********************************/




//================================= Mission Tasking for Players

CA_Task = [WEST, "Repent Counter Attack",[_missionBriefing,"Repent Counter Attack",MAINAOLOC],getmarkerpos MAINAOLOC,"created",10,true,"Defend",true] call BIS_fnc_taskCreate;


//================================= Spawning Enemies

_counterAttackers = creategroup east;
_spawnLoc = [(getMarkerPos "csat_base"),random 5,0] call BIS_fnc_relPos;

//============== Vehicles
_spawnLoc = [_spawnLoc,1,10,10,0,40,0] call BIS_fnc_findSafePos;
_marid = createVehicle ["O_APC_Wheeled_02_rcws_F", _spawnLoc,_nullArray,1,"FORM"];
sleep 2;
_spawnLoc = [_spawnLoc,1,10,10,0,40,0] call BIS_fnc_findSafePos;
_tigris = createVehicle ["O_APC_Tracked_02_AA_F", _spawnLoc,_nullArray,1,"FORM"];
sleep 2;
_spawnLoc = [_spawnLoc,1,10,10,0,40,0] call BIS_fnc_findSafePos;
_tempest1 = createVehicle ["O_Truck_03_covered_F", _spawnLoc,_nullArray,1,"FORM"];
sleep 2;
_spawnLoc = [_spawnLoc,1,10,10,0,40,0] call BIS_fnc_findSafePos;
_tempest2 = createVehicle ["O_Truck_03_covered_F", _spawnLoc,_nullArray,1,"FORM"];
sleep 2;
_spawnLoc = [_spawnLoc,1,10,10,0,40,0] call BIS_fnc_findSafePos;
_tempest3 = createVehicle ["O_Truck_03_covered_F", _spawnLoc,_nullArray,1,"FORM"];

//==============Marid Crew

private _mSquad = ["_unit0","_unit1","_unit2","_unit3","_unit4","_unit5","_unit6","_unit7","_unit8","_unit9","_unit10"];
_unit0 = [_counterAttackers,"O_Soldier_SL_F",_spawnLoc,"SQUADLEADER"] call YI_fnc_spawnAiUnit;
_unit1 = [_counterAttackers,"O_medic_F",_spawnLoc,"MEDIC"] call YI_fnc_spawnAiUnit;
_unit2 = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;
_unit3 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_unit4 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_unit5 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_unit6 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_unit7 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_unit8 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_unit9 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_unit10 =[_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;

_unit4 moveinDriver _marid;
_unit3 moveinGunner _marid;

_unit0 moveinCommander _marid;
_unit1 moveinCargo _marid;
_unit2 moveinCargo _marid;
_unit5 moveinCargo _marid;
_unit6 moveinCargo _marid;
_unit7 moveinCargo _marid;
_unit8 moveinCargo _marid;
_unit9 moveinCargo _marid;
_unit10 moveinCargo _marid;



//==============Tigris


private _tigSquad = ["_tigDriver","_tigCommand","_tigGunner"];
_tigCommand = [_counterAttackers,"O_Soldier_TL_F",_spawnLoc,"SQUADLEADER"] call YI_fnc_spawnAiUnit;
_tigDriver = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_tigGunner = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;

_tigCommand moveinCommander _tigris;
_tigGunner moveInGunner _tigris;
_tigDriver moveinDriver _tigris;



//==============Tempest1


private _t1Squad = ["_t1Driver","_t1Medic1","_t1Medic2","_t1Engineer3","_t1Engineer4","_t1Pass5","_t1Pass6","t1Pass7","_t1Pass8","_t1Pass9","_t1Pass10","_t1Pass11","_t1Pass12","_t1Pass13"];

_t1Driver = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Medic1 = [_counterAttackers,"O_medic_F",_spawnLoc,"MEDIC"] call YI_fnc_spawnAiUnit;
_t1Medic2 = [_counterAttackers,"O_medic_F",_spawnLoc,"MEDIC"] call YI_fnc_spawnAiUnit;
_t1Engineer3 = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;
_t1Engineer4 = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;
_t1Pass5 = [_counterAttackers,"O_Soldier_TL_F",_spawnLoc,"SQUADLEADER"] call YI_fnc_spawnAiUnit;
_t1Pass6 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Pass7 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Pass8 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Pass9 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Pass10 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Pass11 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Pass12 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t1Pass13 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;

_t1Pass5 moveinDriver _tempest1;
_t1Medic1 moveinCargo _tempest1;
_t1Medic2 moveinCargo _tempest1;
_t1Engineer3 moveinCargo _tempest1;
_t1Engineer4 moveinCargo _tempest1;
_t1Pass5 moveinCargo _tempest1;
_t1Pass6 moveinCargo _tempest1;
_t1Pass7 moveinCargo _tempest1;
_t1Pass8 moveinCargo _tempest1;
_t1Pass9 moveinCargo _tempest1;
_t1Pass10 moveinCargo _tempest1;
_t1Pass11 moveinCargo _tempest1;
_t1Pass12 moveinCargo _tempest1;
_t1Pass13 moveinCargo _tempest1;



//==============Tempest2

private _t2Squad = ["_t2Driver","_t2Medic1","_t2Medic2","_t2Engineer3","_t2Engineer4","_t2Pass5","_t2Pass6","t1Pass7","_t2Pass8","_t2Pass9","_t2Pass10","_t2Pass11","_t2Pass12","_t2Pass13"];

_t2Driver = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Medic1 = [_counterAttackers,"O_medic_F",_spawnLoc,"MEDIC"] call YI_fnc_spawnAiUnit;
_t2Medic2 = [_counterAttackers,"O_medic_F",_spawnLoc,"MEDIC"] call YI_fnc_spawnAiUnit;
_t2Engineer3 = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;
_t2Engineer4 = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;
_t2Pass5 = [_counterAttackers,"O_Soldier_TL_F",_spawnLoc,"SQUADLEADER"] call YI_fnc_spawnAiUnit;
_t2Pass6 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Pass7 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Pass8 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Pass9 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Pass10 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Pass11 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Pass12 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t2Pass13 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;

_t2Pass5 moveinDriver _tempest2;
_t2Medic1 moveinCargo _tempest2;
_t2Medic2 moveinCargo _tempest2;
_t2Engineer3 moveinCargo _tempest2;
_t2Engineer4 moveinCargo _tempest2;
_t2Pass5 moveinCargo _tempest1;
_t2Pass6 moveinCargo _tempest2;
_t2Pass7 moveinCargo _tempest2;
_t2Pass8 moveinCargo _tempest2;
_t2Pass9 moveinCargo _tempest2;
_t2Pass10 moveinCargo _tempest2;
_t2Pass11 moveinCargo _tempest2;
_t2Pass12 moveinCargo _tempest2;
_t2Pass13 moveinCargo _tempest2;


//==============Tempest3


private _t2Squad = ["_t2Driver","_t2Medic1","_t2Medic2","_t2Engineer3","_t2Engineer4","_t2Pass5","_t2Pass6","t1Pass7","_t2Pass8","_t2Pass9","_t2Pass10","_t2Pass11","_t2Pass12","_t2Pass13"];

_t3Driver = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Medic1 = [_counterAttackers,"O_medic_F",_spawnLoc,"MEDIC"] call YI_fnc_spawnAiUnit;
_t3Medic2 = [_counterAttackers,"O_medic_F",_spawnLoc,"MEDIC"] call YI_fnc_spawnAiUnit;
_t3Engineer3 = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;
_t3Engineer4 = [_counterAttackers,"O_engineer_F",_spawnLoc,"ENGINEER"] call YI_fnc_spawnAiUnit;
_t3Pass5 = [_counterAttackers,"O_Soldier_TL_F",_spawnLoc,"SQUADLEADER"] call YI_fnc_spawnAiUnit;
_t3Pass6 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Pass7 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Pass8 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Pass9 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Pass10 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Pass11 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Pass12 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;
_t3Pass13 = [_counterAttackers,"O_Soldier_F",_spawnLoc,"RIFLEMAN"] call YI_fnc_spawnAiUnit;

_t3Pass5 moveinDriver _tempest3;
_t3Medic1 moveinCargo _tempest3;
_t3Medic2 moveinCargo _tempest3;
_t3Engineer3 moveinCargo _tempest3;
_t3Engineer4 moveinCargo _tempest3;
_t3Pass5 moveinCargo _tempest1;
_t3Pass6 moveinCargo _tempest3;
_t3Pass7 moveinCargo _tempest3;
_t3Pass8 moveinCargo _tempest3;
_t3Pass9 moveinCargo _tempest3;
_t3Pass10 moveinCargo _tempest3;
_t3Pass11 moveinCargo _tempest3;
_t3Pass12 moveinCargo _tempest3;
_t3Pass13 moveinCargo _tempest3;


//======================= Tasking AIs
private _attackStatus = [_counterAttackers, getMarkerPos MAINAOLOC] call BIS_fnc_taskAttack;
_counterAttackers setFormation "COLUMN";
_counterAttackers setBehaviour "Safe";
_counterAttackers setSpeedMode "Limited";

//======================= Tracking AIs
[_counterAttackers] call YI_fnc_counterAiTracker;

//============== Mission status
private ["_allUnits","_areTheyDead","_trigger"];
_allUnits = units _counterAttackers;

_trigger = createTrigger ["EmptyDetector", getMarkerPos MAINAOLOC];
_trigger setTriggerArea [400, 400, 0, false];
_trigger setTriggerActivation ["EAST", "PRESENT", false];
_trigger setTriggerStatements ["this","",""];

waitUntil {

    sleep 1;
    _aliveUnits = _allUnits select {alive _x};
    _areTheyDead = (count _aliveUnits);

    (_areTheyDead < 5) or (triggerActivated _trigger)
};

//======================== Mission Ending

if (_areTheyDead < 5) then {
	sleep 10;

	private ["_textArray","_title","_text1","_text2","_text3","_text4"];
	_text1 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>HA HAAA, City Saved and counter attack repented, CSAT should just retire. Good job Boys. Now you can RTB";
	_text2 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>We got worried for a second their guys that you would not make it. Nice job again.";
	_text3 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>You happy? Well don't be, there is still more of those bastards on the island. RTB to resupply and get back out there.";
	_text4 = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'>Congratualtion boys, you saved the resistance and the city, report back to base and lets all pop one together before the next mission.";
	//*******
	_textArray = [_text1,_text2,_text3,_text4];
	_title = "<t color='#00ff00' size='2' shadow='1' shadowColor='#000000' align='center'>Counter Attack Eliminated</t>";

	_text = _textArray call BIS_fnc_selectRandom;
	hint parseText (_title + _text);

	[CA_Task, "Succeeded",true] spawn BIS_fnc_taskSetState;
}
else {

	sleep 10;
	private ["_textArray","_text","_title"];
	_text = "<br /><t color='#0000ff' size='1.2' shadow='1' shadowColor='#000000' align='center'> They managed to get into the city, i am sorry boys but there is nothing that can be done now. RTB. We lost this battle.";
	_title = "<t color='#00ff00' size='2' shadow='1' shadowColor='#000000' align='center'>Counter Attack Failed</t>";
	hint parseText (_title + _text);
	[CA_Task, "Failed",true] spawn BIS_fnc_taskSetState;

};

{
	_null2 = damage _x;
	if (_null2 < 1) then {
		_null2 = _x setDamage 1;
	};

}foreach units _counterAttackers;

deleteGroup _counterAttackers;

 

Share this post


Link to post
Share on other sites

How to replace copy-paste with primitive logic and make your code shorter:

SpawnGroupAndBoardVehicle = {
	params ["_vehicle", "_location", "_side", "_unitTypes", "_unitSeats"];
	
	private _group = createGroup _side;
	
	{
		private _class = switch (_x) do {
			case "SQUADLEADER":		{"O_Soldier_TL_F"};
			case "RIFLEMAN":		{"O_Soldier_F"};
			case "ENGINEER":		{"O_engineer_F"};
			case "MEDIC":			{"O_medic_F"};          
			default {throw (format ["Unknown unit type: %1", _x])};
		};		
		[_group, _class, _location, _x] call YI_fnc_spawnAiUnit;
	} forEach _unitTypes;
	
	{
		private _seat = _unitSeats param [_forEachIndex, "CARGO"];
		switch (_seat) do {
			case "DRIVER":		{_x moveinDriver _vehicle};
			case "GUNNER":		{_x moveinGunner _vehicle};
			case "COMMANDER":	{_x moveinCommander _vehicle};
			case "CARGO":		{_x moveinCargo _vehicle};
			default {throw (format ["Unknown unit seat: %1", _seat])};
		}
	} forEach (units _group);
	
	_group;
};



//==============Tigris
private _tigSquad = [_tigris, _spawnLoc, EAST,
	["SQUADLEADER","RIFLEMAN","ENGINEER"], ["COMMANDER", "GUNNER", "DRIVER"]] call SpawnGroupAndBoardVehicle;


//==============Marid
private _mSquad = [_marid, _spawnLoc, EAST,
	["SQUADLEADER", "MEDIC", "ENGINEER","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN"],
	["COMMANDER", "CARGO", "CARGO", "GUNNER", "DRIVER"]] call SpawnGroupAndBoardVehicle;

* code is not debugged

* fixed switch default behavior, thanks killzone_kid

  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, serena said:

default {throw


throw produces error if used outside of try catch construct

Share this post


Link to post
Share on other sites
37 minutes ago, killzone_kid said:

throw produces error if used outside of try catch construct

Since we can not expect that someone will use try/catch in entry points, it is better simply to remove throw command.

 

Updated: code in init.sqf:

ABC = 2;
XYZ = switch (ABC) do {
	case 1: {"Hello"};
	case 2: {"World"};
	default {throw "Error!!!"};
};
// Result: XYZ = "World", no errors
ABC = 3;
XYZ = switch (ABC) do {
	case 1: {"Hello"};
	case 2: {"World"};
	default {throw "Error!!!"};
};
//Result: XYZ = nil, script terminated with error message: 16:46:02   Error Unhandled exception: "Error!!!"

And this is what we need - script termination with a clear error message.

 

 

 

Share this post


Link to post
Share on other sites
26 minutes ago, serena said:

it is better simply to remove


switch without default returns true when no match found. don't think you would want that

Share this post


Link to post
Share on other sites
19 minutes ago, killzone_kid said:


In our case throw is a right choice, because we do not want to repair something. We need to instantly kill broken script, before it can damage something else, and inform user about error.

 

21 minutes ago, killzone_kid said:

switch without default returns true when no match found. don't think you would want that

Right. Script corrected to reflect this.

 

Share this post


Link to post
Share on other sites
21 minutes ago, serena said:

We need to instantly kill broken script, before it can damage something else, and inform user about error.


It's a hack, but I like it

Share this post


Link to post
Share on other sites
2 hours ago, serena said:

How to replace copy-paste with primitive logic and make your code shorter:


SpawnGroupAndBoardVehicle = {
	params ["_vehicle", "_location", "_side", "_unitTypes", "_unitSeats"];
	
	private _group = createGroup _side;
	
	{
		private _class = switch (_x) do {
			case "SQUADLEADER":		{"O_Soldier_TL_F"};
			case "RIFLEMAN":		{"O_Soldier_F"};
			case "ENGINEER":		{"O_engineer_F"};
			case "MEDIC":			{"O_medic_F"};          
			default {throw (format ["Unknown unit type: %1", _x])};
		};		
		[_group, _class, _location, _x] call YI_fnc_spawnAiUnit;
	} forEach _unitTypes;
	
	{
		private _seat = _unitSeats param [_forEachIndex, "CARGO"];
		switch (_seat) do {
			case "DRIVER":		{_x moveinDriver _vehicle};
			case "GUNNER":		{_x moveinGunner _vehicle};
			case "COMMANDER":	{_x moveinCommander _vehicle};
			case "CARGO":		{_x moveinCargo _vehicle};
			default {throw (format ["Unknown unit seat: %1", _seat])};
		}
	} forEach (units _group);
	
	_group;
};



//==============Tigris
private _tigSquad = [_tigris, _spawnLoc, EAST,
	["SQUADLEADER","RIFLEMAN","ENGINEER"], ["COMMANDER", "GUNNER", "DRIVER"]] call SpawnGroupAndBoardVehicle;


//==============Marid
private _mSquad = [_marid, _spawnLoc, EAST,
	["SQUADLEADER", "MEDIC", "ENGINEER","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN","RIFLEMAN"],
	["COMMANDER", "CARGO", "CARGO", "GUNNER", "DRIVER"]] call SpawnGroupAndBoardVehicle;

* code is not debugged

* fixed switch default behavior, thanks killzone_kid

 

OMG, without you guys I would have given up on Arma scripting ages ago. You guys are seriously the best. Not only did you guys help fix my codes, most of them were taught to me by you and above all you give me better alternatives.

 

Thank you @serena and @killzone_kid

Share this post


Link to post
Share on other sites

_trigger = createTrigger ["EmptyDetector", getMarkerPos MAINAOLOC];
_trigger setTriggerArea [400, 400, 0, false];
_trigger setTriggerStatements ["this","",""];
_trigger triggerAttachVehicle [ leader group _counterAttackers ];
_trigger setTriggerActivation ["GROUP", "PRESENT", false];

Attach the leader of _counterAttackers to the trigger and set it to GROUP. Trigger will activate when all alive group members are inside the trigger.

Or you can use

"MEMBER" any of the groups units are inside the trigger.

"LEADER" when the group leader is in the trigger.

 

 

 

11 hours ago, killzone_kid said:

throw produces error if used outside of try catch construct

 

It's a hack, but I like it

Why do you call it a hack? Throw is a unary command. Although useful within a Try Catch statement it is not tied to this syntax. Its doing what it was designed to do, produce an error.

 

  • Thanks 1

Share this post


Link to post
Share on other sites
30 minutes ago, Larrow said:

 


_trigger = createTrigger ["EmptyDetector", getMarkerPos MAINAOLOC];
_trigger setTriggerArea [400, 400, 0, false];
_trigger setTriggerStatements ["this","",""];
_trigger triggerAttachVehicle [ leader group _counterAttackers ];
_trigger setTriggerActivation ["GROUP", "PRESENT", false];

 

Attach the leader of _counterAttackers to the trigger and set it to GROUP. Trigger will activate when all alive group members are inside the trigger.

Or you can use

"MEMBER" any of the groups units are inside the trigger.

"LEADER" when the group leader is in the trigger.

 

3

Thanks Larrow. That is what i need :D

Share this post


Link to post
Share on other sites
5 hours ago, Larrow said:

 

 

Why do you call it a hack? Throw is a unary command. Although useful within a Try Catch statement it is not tied to this syntax. Its doing what it was designed to do, produce an error.

 

 

It wasn't designed to produce an error. It wasn't designed to be used outside of try catch construct. It was however designed to terminate the code. Using something not quite as intended is a hack. In this case it happened to be that error message also matches the intention, while all it is saying that the command used out of construct and therefore exception is not caught.

Share this post


Link to post
Share on other sites
4 hours ago, killzone_kid said:

It wasn't designed to produce an error. It wasn't designed to be used outside of try catch construct

No it was designed to produce an exception. An exception is an event that an error occurred and if not handled will terminate with unhandled exception error.

It was introduced in the 70s as to complement along side pre-existing commands like ERR/ERRSET by enabling the raising of exceptions so that it may be caught by a try, catch structure.

The point I was trying to get across is that it is not mutually exclusive to try catch and is its own command that is perfectly valid syntax without a try catch. If not caught it will result in program termination and error which is exactly how Serena has used it.

 

 

Share this post


Link to post
Share on other sites
6 minutes ago, Larrow said:

No it was designed to produce an exception. An exception is an event that an error occurred and if not handled will terminate with unhandled exception error.

It was introduced in the 70s as to complement along side pre-existing commands like ERR/ERRSET by enabling the raising of exceptions so that it may be caught by a try, catch structure.

The point I was trying to get across is that it is not mutually exclusive to try catch and is it own command that is perfectly valid syntax without a try catch. If not caught it will result in program termination and error which is exactly how Serena has used it.

 

 


I thought we were talking about Arma implementation. The error message Unhandled Exception is generated when throw is used out of try catch scope. It is actually a script error. But as I said, it terminates the code because error is generated after throw command is used and this is why it is a "good" script error.

Share this post


Link to post
Share on other sites
5 minutes ago, killzone_kid said:

I thought we were talking about Arma implementation.

No I was just generalising :) tbh I rarely use those commands in Arma.

 

14 minutes ago, killzone_kid said:

The error message Unhandled Exception is generated when throw is used out of try catch scope

Which is the same as C#, if used with no catch to handle it. Its not complaining that throw was used outside try catch but that the exception was unhandled, as it actually states that in the error. If it was a usage problem then I would expect a General error or some specific command usage problem.

Share this post


Link to post
Share on other sites
11 minutes ago, Larrow said:

No I was just generalising :) tbh I rarely use those commands in Arma.

 

Which is the same as C#, if used with no catch to handle it. Its not complaining that throw was used outside try catch but that the exception was unhandled, as it actually states that in the error. If it was a usage problem then I would expect a General error or some specific command usage problem.


I wouldn't bet on it if the intention was to make try/catch work like it works in other languages and catch script errors without displaying them but handling them with catch, but it doesn't work that way. In Arma the error generated is definitely a script error and definitely because no catch scope exists.

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

×