Solidsnacks 10 Posted December 4, 2019 I have a switch statement that fails to return any of the cases and instead returns default. I've used different classnames for default and they work successfully but the cases fail to return when called. The script is copied (the entire file TBH) from BI's 'Escape from Malden' initServer.sqf with the only changes being the changes to the classnames the cases reference. My initServer.sqf edit: Spoiler // NATO patrolling vehicles if (triggerText _x == "NATO_patrolVeh") then { _x spawn { _basePos = position _this; _dir = (triggerArea _this) select 2; if (_dir < 0) then {_dir = 360 + _dir}; _vehType = (triggerStatements _this) select 1; _wpPath = group ((synchronizedObjects _this) select 0); // synchronized civilian unit is used as waypoint storage deleteVehicle ((synchronizedObjects _this) select 0); deleteVehicle _this; waitUntil {sleep 2.5; ({(_x distance _basePos) < 1000} count allPlayers > 0)}; _vehClass = switch (_vehType) do { case "MRAP": {"gmx_tak_army_bdrm2_des"}; case "APC": {"gmx_tak_army_bmp1sp2_des"}; case "IFV": {"gmx_tak_army_btr60pb_des"}; case "LSVU": {"gmx_tak_army_btr60pa_des"}; default {"gmx_tak_army_btr60pa_des"}; }; _veh = createVehicle [_vehClass, _basePos, [], 0, "NONE"]; _veh setDir _dir; createVehicleCrew _veh; _vehCrew = crew _veh; _vehGroup = group (_vehCrew select 0); _vehGroup copyWaypoints _wpPath; deleteGroup _wpPath; {clearMagazineCargoGlobal _x; clearWeaponCargoGlobal _x; clearBackpackCargoGlobal _x; clearItemCargoGlobal _x} forEach [_veh]; _veh addItemCargoGlobal ["FirstAidKit",2]; _veh setFuel (0.2 + random 0.2); _veh setVehicleAmmo (0.4 + random 0.4); // If the vehicle is unarmed LSV, create crew for FFV positions and disable getting out in combat if (_vehType == "LSVU") then { _veh setUnloadInCombat [false,false]; _unit01 = _vehGroup createUnit ["gmx_tak_army_machinegunner_rpk_oli", [0,0,0], [], 0, "CAN_COLLIDE"]; _unit01 moveInCargo _veh; [_unit01] orderGetIn true; _unit02 = _vehGroup createUnit ["gmx_tak_army_grenadier_g3a3_oli", [0,0,0], [], 0, "CAN_COLLIDE"]; _unit02 moveInCargo _veh; [_unit02] orderGetIn true; _unit03 = _vehGroup createUnit ["gmx_tak_army_rifleman_g3a3_oli", [0,0,0], [], 0, "CAN_COLLIDE"]; _unit03 moveInCargo _veh; [_unit03] orderGetIn true; _vehCrew = crew _veh; }; // Handle immobilization if (missionNamespace getVariable "BIS_crewInImmobile" == 1) then { _veh allowCrewInImmobile true; }; /* // Chance to create a second vehicle of the same type - only for armed LSV and UGV if ((_vehType in ["UGV","LSV"]) and {random 100 < 35}) then { _veh02 = createVehicle [_vehClass, [(_basePos select 0) - 7, (_basePos select 1) - 7, 0], [], 0, "NONE"]; _veh02 setDir _dir; createVehicleCrew _veh02; _veh02Crew = crew _veh02; _veh02Crew joinSilent _vehGroup; {clearMagazineCargoGlobal _x; clearWeaponCargoGlobal _x; clearBackpackCargoGlobal _x; clearItemCargoGlobal _x} forEach [_veh02]; _veh02 addItemCargoGlobal ["FirstAidKit",2]; _veh02 setFuel (0.1 + random 0.1); _veh02 setVehicleAmmo (0.4 + random 0.4); // Handle immobilization if (missionNamespace getVariable "BIS_crewInImmobile" == 1) then { _veh02 allowCrewInImmobile true; }; }; */ // Limit unit equipment if set by server if ((missionNamespace getVariable "BIS_enemyEquipment" == 1) and {_vehType != "UGV"}) then {{_null = _x execVM "Scripts\LimitEquipment.sqf"} forEach (units _vehGroup)}; // Limit aiming accuracy {_x setSkill ["AimingAccuracy",0.1]} forEach (units _vehGroup); // Enable Dynamic simulation _vehGroup enableDynamicSimulation true; }; }; The original unedited version: Spoiler // NATO patrolling vehicles if (triggerText _x == "NATO_patrolVeh") then { _x spawn { _basePos = position _this; _dir = (triggerArea _this) select 2; if (_dir < 0) then {_dir = 360 + _dir}; _vehType = (triggerStatements _this) select 1; _wpPath = group ((synchronizedObjects _this) select 0); // synchronized civilian unit is used as waypoint storage deleteVehicle ((synchronizedObjects _this) select 0); deleteVehicle _this; waitUntil {sleep 2.5; ({(_x distance _basePos) < 1000} count allPlayers > 0)}; _vehClass = switch (_vehType) do { case "MRAP": {selectRandom ["B_MRAP_01_gmg_F","B_MRAP_01_hmg_F"]}; case "APC": {"B_APC_Tracked_01_rcws_F"}; case "IFV": {"B_APC_Wheeled_01_cannon_F"}; case "AAA": {"B_APC_Tracked_01_AA_F"}; case "LSV": {"B_LSV_01_armed_F"}; case "LSVU": {"B_LSV_01_unarmed_F"}; case "UGV": {"B_UGV_01_rcws_F"}; case "Boat": {"B_Boat_Armed_01_minigun_F"}; default {"B_LSV_01_armed_F"}; }; _veh = createVehicle [_vehClass, _basePos, [], 0, "NONE"]; _veh setDir _dir; createVehicleCrew _veh; _vehCrew = crew _veh; _vehGroup = group (_vehCrew select 0); _vehGroup copyWaypoints _wpPath; deleteGroup _wpPath; {clearMagazineCargoGlobal _x; clearWeaponCargoGlobal _x; clearBackpackCargoGlobal _x; clearItemCargoGlobal _x} forEach [_veh]; _veh addItemCargoGlobal ["FirstAidKit",2]; _veh setFuel (0.2 + random 0.2); _veh setVehicleAmmo (0.4 + random 0.4); // If the vehicle is unarmed LSV, create crew for FFV positions and disable getting out in combat if (_vehType == "LSVU") then { _veh setUnloadInCombat [false,false]; _unit01 = _vehGroup createUnit ["B_Soldier_AR_F", [0,0,0], [], 0, "CAN_COLLIDE"]; _unit01 moveInCargo _veh; [_unit01] orderGetIn true; _unit02 = _vehGroup createUnit [selectRandom ["B_Soldier_GL_F","B_Soldier_F"], [0,0,0], [], 0, "CAN_COLLIDE"]; _unit02 moveInCargo _veh; [_unit02] orderGetIn true; _unit03 = _vehGroup createUnit ["B_Soldier_F", [0,0,0], [], 0, "CAN_COLLIDE"]; _unit03 moveInCargo _veh; [_unit03] orderGetIn true; _vehCrew = crew _veh; }; // Handle immobilization if (missionNamespace getVariable "BIS_crewInImmobile" == 1) then { _veh allowCrewInImmobile true; }; /* // Chance to create a second vehicle of the same type - only for armed LSV and UGV if ((_vehType in ["UGV","LSV"]) and {random 100 < 35}) then { _veh02 = createVehicle [_vehClass, [(_basePos select 0) - 7, (_basePos select 1) - 7, 0], [], 0, "NONE"]; _veh02 setDir _dir; createVehicleCrew _veh02; _veh02Crew = crew _veh02; _veh02Crew joinSilent _vehGroup; {clearMagazineCargoGlobal _x; clearWeaponCargoGlobal _x; clearBackpackCargoGlobal _x; clearItemCargoGlobal _x} forEach [_veh02]; _veh02 addItemCargoGlobal ["FirstAidKit",2]; _veh02 setFuel (0.1 + random 0.1); _veh02 setVehicleAmmo (0.4 + random 0.4); // Handle immobilization if (missionNamespace getVariable "BIS_crewInImmobile" == 1) then { _veh02 allowCrewInImmobile true; }; }; */ // Limit unit equipment if set by server if ((missionNamespace getVariable "BIS_enemyEquipment" == 1) and {_vehType != "UGV"}) then {{_null = _x execVM "Scripts\LimitEquipment.sqf"} forEach (units _vehGroup)}; // Limit aiming accuracy {_x setSkill ["AimingAccuracy",0.1]} forEach (units _vehGroup); // Enable Dynamic simulation _vehGroup enableDynamicSimulation true; }; }; Share this post Link to post Share on other sites
pierremgi 4902 Posted December 4, 2019 _vehType = (triggerStatements _this) select 1; That means you need to use the same statements as triggers embedded in the BI mission. If not, "MRAP", "APC", "IFV"... will not have sense. Share this post Link to post Share on other sites
Solidsnacks 10 Posted December 4, 2019 Right. I should have mentioned that I use the cases in the trigger statements from empty detector triggers in the editor. I’ve reviewed everything and it’s all 1:1. Would anyone like to reproduce this on their end? Share this post Link to post Share on other sites
Dedmen 2714 Posted December 5, 2019 Plaster your code with diag_log's log _vehType right before the switch and check that it really contains what you expect it to contain. Trust me switch is not broken, that would've been noticed over the 13+ years of its existance. There is some error in your script, most likely _vehType not being what you think it is. Share this post Link to post Share on other sites
killzone_kid 1331 Posted December 5, 2019 triggerStatements select 1 will return on activation statement. MRAP is not on activation statement Share this post Link to post Share on other sites
Solidsnacks 10 Posted December 5, 2019 Thanks everyone for chiming in. Much respect to all of you. @killzone_kid I get what you mean by “select 1” returns the “on activation” statement. The part that’s messing me up is that I have the triggers configured identically to the ones in the original escape scenario so I’m really at a loss for why it wouldn’t give me the same output as the original. The original triggers simply have MRAP, APC etc (no quotes “ “ or anything) in the “on act.” block. So I’m not sure if you meant something else in your last sentence. @dedmen I had a friend tell me the same thing so I’ll have to see if something pops up in the logs ‘cause it’s not throwing any errors or anything that I can see in the rpt—if that’s even a thing. Thanks again, all! I’ll update when I get home and can check it out. Share this post Link to post Share on other sites
Solidsnacks 10 Posted December 16, 2019 Hey all. I took a couple of weeks away to rethink what was going on and decided to look in the mission.sqm to see if there was anything different about the triggers and their statements. I found this Spoiler class Item31 { dataType="Trigger"; position[]={3384.407,5.9899998,7193.21}; angle=1.0791019; class Attributes { text="NATO_patrolVeh"; condition="call{this}"; onActivation="call{MRAP}"; sizeA=5; sizeB=10; isRectangle=1; }; id=177; type="EmptyDetector"; }; I decided to compare it to the original mission.sqm and found this. Spoiler class Item10 { dataType="Trigger"; position[]={7050.4883,100.47604,6533.5054}; class Attributes { text="NATO_patrolVeh"; onActivation="MRAP"; sizeA=5; sizeB=10; isRectangle=1; }; id=268; type="EmptyDetector"; }; The interesting part is the changes in the "condition" and "onActivation" fields. I went into the mission.sqm and manually changed them to match the original and got the desired behavior from my switch statement. Once again, the trigger is directly copied from the original mission so I get the feeling this isn't how it's supposed to work. When I load the mission it changes the trigger "cond." and "onAct.". Does anyone know why this is happening and/or how to prevent it? Share this post Link to post Share on other sites
pierremgi 4902 Posted December 16, 2019 That doesn't have any importance. Most of the imported triggers have onAct. onDeact. and cond. codes wrapped in call {...} with the new editor. Your problem is that MRAP is not a code, neither in old, nor new syntax for sqm. So, try to understand what occurred with the onAct. code. It's definitely broken. What I guess is, perhaps somewhere in scenario, NATO_patrol_Veh is "related" to MRAP . 2 variables?? why in a trigger?? MRAP is not a vehicle class, so did you find this variable? or string chain? somewhere else inside an sqf or in a name of file? It's always difficult to modify the work of someone else (even with permission). Share this post Link to post Share on other sites
Larrow 2822 Posted December 17, 2019 6 hours ago, pierremgi said: Most of the imported triggers have onAct. onDeact. and cond. codes wrapped in call {...} with the new editor. No they do not. 8 hours ago, Solidsnacks said: When I load the mission it changes the trigger "cond." and "onAct.". Does anyone know why this is happening and/or how to prevent it? CBA adds the call{ attribute } into multicode attributes. 1 Share this post Link to post Share on other sites
Solidsnacks 10 Posted December 17, 2019 Nice catch @Larrow! Another thing I’ve noticed is the trigger attributes can be modified and saved in the mission.sqm. Then you can load/ save, and preview the mission without the attributes changing, but the moment you start changing any of the trigger properties in the editor it will add the call {attribute}. Seeing how I’m only using a small number of these—-and don’t mind manually changing them in the editor—-I consider my problem solved. For the sake of anyone else that might struggle with something similar; can you suggest somewhere to start looking to learn how to restrict that behavior? Share this post Link to post Share on other sites