DeadWeight85 1 Posted March 9, 2014 I am having a hard time understanding using cases and switches. I am trying to make it so that when the case it called it needs have 2 items to continue onto the next part. Here is an example: _vendor = [_this,0,ObjNull,[ObjNull]] call BIS_fnc_param;_type = [_this,3,"",[""]] call BIS_fnc_param;//Error checkif(isNull _vendor OR _type == "" OR (player distance _vendor > 10)) exitWith {};//unprocessed item,processed item, cost if no license,Text to display (I.e Processing (percent) ..."_itemInfo = switch (_type) do{ case "sand": {["sand","glass",70,"Processing Sand"]}; default {[]};};[/Code]I am trying to get something like this case "sand": {["sand" && "water","glass",70,"Processing Sand"]}; Can anyone point me in the right direction? Share this post Link to post Share on other sites
Von Quest 1161 Posted March 9, 2014 _itemInfo = switch (_type) do { case ("sand"): {["sand","glass",70,"Processing Sand"]}; default {[]}; }; Share this post Link to post Share on other sites
DeadWeight85 1 Posted March 9, 2014 So Goblin how by adding the () will that allow me to place 2 items in my case? Share this post Link to post Share on other sites
Zenophon 110 Posted March 9, 2014 A switch statement compares the given value ('_type' in this case) to each case value ("sand" literal in your case). This comparison is equivalent to: (_type == "sand") The expression at each case need not be a literal, or even a single variable. Consider this: switch (true) do { case (_type in ["sand", "water"]): { // do something }; } The check for this case becomes: (true == (_type in ["sand", "water"])) However, I am not sure if this is what you really want your function to do. You need to be more specific about what this function is meant to do and where you are using it. If you want to return multiple strings as the first element of the array, you would just use a nested array: [["sand","water"],"glass",70,"Processing Sand"] The && operator is the boolean 'and' operation; you can only apply it to boolean types. Share this post Link to post Share on other sites
DeadWeight85 1 Posted March 11, 2014 Zenophon I am editing the Altis Life mission file, and in particular the processAction script. I am trying to make it a little more realistic and having the player need 2 items to process into 1. /* File: fn_processAction.sqf Author: Bryan "Tonic" Boardwine Description: Master handling for processing an item.*/private["_vendor","_type","_itemInfo","_oldItem","_newItem","_cost","_upp","_hasLicense","_itemName","_oldVal","_ui","_progress","_pgText","_cP"];_vendor = [_this,0,ObjNull,[ObjNull]] call BIS_fnc_param;_type = [_this,3,"",[""]] call BIS_fnc_param;//Error checkif(isNull _vendor OR _type == "" OR (player distance _vendor > 10)) exitWith {};//unprocessed item,processed item, cost if no license,Text to display (I.e Processing (percent) ..."_itemInfo = switch (_type) do{ case "sand": {["sand","glass",70,"Processing Sand"]}; default {[]};};//Error checkingif(count _itemInfo == 0) exitWith {};//Setup vars._oldItem = _itemInfo select 0;_newItem = _itemInfo select 1;_cost = _itemInfo select 2;_upp = _itemInfo select 3;_hasLicense = missionNamespace getVariable (([_type,0] call life_fnc_licenseType) select 0);_itemName = [([_newItem,0] call life_fnc_varHandle)] call life_fnc_varToStr;_oldVal = missionNamespace getVariable ([_oldItem,0] call life_fnc_varHandle);_cost = _cost * _oldVal;//Some more checksif(_oldVal == 0) exitWith {};//Setup our progress bar.disableSerialization;5 cutRsc ["life_progress","PLAIN"];_ui = uiNameSpace getVariable "life_progress";_progress = _ui displayCtrl 38201;_pgText = _ui displayCtrl 38202;_pgText ctrlSetText format["%2 (1%1)...","%",_upp];_progress progressSetPosition 0.01;_cP = 0.01;life_is_processing = true;if(_hasLicense) then{ while{true} do { sleep 0.3; _cP = _cP + 0.01; _progress progressSetPosition _cP; _pgText ctrlSetText format["%3 (%1%2)...",round(_cP * 100),"%",_upp]; if(_cP >= 1) exitWith {}; if(player distance _vendor > 10) exitWith {}; }; if(player distance _vendor > 10) exitWith {hint "You need to stay within 10m to process."; 5 cutText ["","PLAIN"]; life_is_processing = false;}; if(!([false,_oldItem,_oldVal] call life_fnc_handleInv)) exitWith {5 cutText ["","PLAIN"]; life_is_processing = false;}; if(!([true,_newItem,_oldVal] call life_fnc_handleInv)) exitWith {5 cutText ["","PLAIN"]; [true,_oldItem,_oldVal] call life_fnc_handleInv; life_is_processing = false;}; 5 cutText ["","PLAIN"]; titleText[format["You have processed %1 into %2",_oldVal,_itemName],"PLAIN"]; life_is_processing = false;} else{ if(life_cash < _cost) exitWith {hint format["You need $%1 to process without a license!",[_cost] call life_fnc_numberText]; 5 cutText ["","PLAIN"]; life_is_processing = false;}; while{true} do { sleep 0.9; _cP = _cP + 0.01; _progress progressSetPosition _cP; _pgText ctrlSetText format["%3 (%1%2)...",round(_cP * 100),"%",_upp]; if(_cP >= 1) exitWith {}; if(player distance _vendor > 10) exitWith {}; }; if(player distance _vendor > 10) exitWith {hint "You need to stay within 10m to process."; 5 cutText ["","PLAIN"]; life_is_processing = false;}; if(life_cash < _cost) exitWith {hint format["You need $%1 to process without a license!",[_cost] call life_fnc_numberText]; 5 cutText ["","PLAIN"]; life_is_processing = false;}; if(!([false,_oldItem,_oldVal] call life_fnc_handleInv)) exitWith {5 cutText ["","PLAIN"]; life_is_processing = false;}; if(!([true,_newItem,_oldVal] call life_fnc_handleInv)) exitWith {5 cutText ["","PLAIN"]; [true,_oldItem,_oldVal] call life_fnc_handleInv; life_is_processing = false;}; 5 cutText ["","PLAIN"]; titleText[format["You have processed %1 into %2 for $%3",_oldVal,_itemName,[_cost] call life_fnc_numberText],"PLAIN"]; life_cash = life_cash - _cost; life_is_processing = false;};[/Code]So I see the portion your talking about having to redo the array and where its called. I will have to give it a try later tonight. Share this post Link to post Share on other sites