Robustcolor 31 Posted January 2, 2020 Hi, how can i pass different arguments to params in the same switch/exitiwith fnc? Examples what i'm trying to do [_patrol] spawn fnc_switch; [_hunt] spawn fnc_switch; fnc_switch = { Params ["???"]; call { if (_patrol) exitWith { //code 1 }; if (_hunt) exitWith { //code 2 }; if (_garrison) exitWith { //code 3 }; //default will be _patrol }; }; Share this post Link to post Share on other sites
7erra 629 Posted January 2, 2020 What datatype (number, string, ...) are _patrol/_hunt/_garrison? Share this post Link to post Share on other sites
Robustcolor 31 Posted January 2, 2020 23 minutes ago, 7erra said: What datatype (number, string, ...) are _patrol/_hunt/_garrison? The thing is i just want to pass an argument to the fnc so it activates one of the if exitwith or cases when one of the condition/name is same as the passed argument. Share this post Link to post Share on other sites
7erra 629 Posted January 2, 2020 Yes I know but that depends on what data type the params are. The information is not enough to work with for me. If it is a string/number/object then comparing these is no problem but it gets harder with code/arrays. Share this post Link to post Share on other sites
Larrow 2823 Posted January 3, 2020 fnc_switch = { //params[ [ "_mode", "PATROL", [ "" ] ] ]; params[ //First var [ "_mode", //variable name "PATROL", //default value [ "" ] //Must be of type STRING ] ]; switch ( toUpper _mode ) do { case "PATROL" : { //Do something }; case "HUNT" : { //Do something }; }; }; [ "PATROL" ] spawn fnc_switch; 1 Share this post Link to post Share on other sites
Robustcolor 31 Posted January 3, 2020 8 hours ago, Larrow said: fnc_switch = { //params[ [ "_mode", "PATROL", [ "" ] ] ]; params[ //First var [ "_mode", //variable name "PATROL", //default value [ "" ] //Must be of type STRING ] ]; switch ( toUpper _mode ) do { case "PATROL" : { //Do something }; case "HUNT" : { //Do something }; }; }; [ "PATROL" ] spawn fnc_switch; Thank you @Larrow I'm combining it like this, might be a more efficient way of doing it. Since i want to have one function that spawns ai but still be able to call different scripts for the different Ai groups. private _m1 = ["GUARD",5,_markerpos,_range] spawn VUnits; private _m2 = ["HUNT",5,_markerpos,_range] spawn VUnits; VUnits = { params [["_mode","GUARD",[""]],"_g","_markerpos","_range"]; for "_i" from 1 to _g do { private _group = createGroup [east, true]; private _pos = [_markerpos, 0, _range, 5, 0, 0.4, 0, [],_markerpos] call BIS_fnc_findSafePos; private _unit = _group createUnit [selectRandom Unitpatrol, _pos, [], 0, "NONE"]; sleep 1; }; switch (toUpper _mode) do { case "GUARD" : { private _Guardscript = [_group,_markerpos] spawn Robust_fnc_Guard; }; case "HUNT" : { private _Attackscript = [_group,_markerpos] spawn Robust_fnc_Attack; }; }; }; Share this post Link to post Share on other sites
Robustcolor 31 Posted January 3, 2020 Since a switch is kinda slow, is it possible to convert it into this call { if (PATROL) exitWith { //code 1 }; if (GUARD) exitWith { //code 2 }; if (GARRISON) exitWith { //code 3 }; //default code }; I also changed toUpper command into toUpperANSI since it could be 3x faster than toUpper. Share this post Link to post Share on other sites
pierremgi 4906 Posted January 4, 2020 Not exactly: params[ [ "_mode", "PATROL", [ "" ] ] ]; call { if (_mode == "PATROL") exitWith { //code 1 }; if (_mode == "GUARD") exitWith { //code 2 }; if (_mode == "GARRISON") exitWith { //code 3 }; //default code }; using == rather than isEqualTo avoids a check for case sensitivity and you will not notice a great difference for code optimization. NB: when you write if (PATROL)... the engine is waiting for ? ? ?? Spoiler a boolean (i.e. TRUE or FALSE) So, you could avoid such error, just reading at the BIKI syntax for EVERY command (at least when you begin). Share this post Link to post Share on other sites
Robustcolor 31 Posted January 4, 2020 Thanks @pierremgi Share this post Link to post Share on other sites
Robustcolor 31 Posted January 8, 2020 On 1/4/2020 at 6:18 AM, pierremgi said: params[ [ "_mode", "PATROL", [ "" ] ] ]; call { if (_mode == "PATROL") exitWith { //code 1 }; if (_mode == "GUARD") exitWith { //code 2 }; if (_mode == "GARRISON") exitWith { //code 3 }; //default code }; Ye i can't say it was any noticeably different from the switch when testing it. Using it with isEqualTo. params[ [ "_mode", "PATROL", [ "" ] ] ]; call { if (_mode isEqualTo "PATROL") exitWith { //code 1 }; if (_mode isEqualTo "GUARD") exitWith { //code 2 }; if (_mode isEqualTo "GARRISON") exitWith { //code 3 }; //default code }; Share this post Link to post Share on other sites