Ramsen III 0 Posted October 11, 2019 Hi all. Why does this switch code not work (No error just no/zero result) it should result in the 25 markers. _marks = []; { _markers = _x; switch (getmarkercolor _markers) do /// Have also tried just 'markercolor _markers' and also assigning to a varible like '_colors = getmarkercolor _markers' and placing the varible in the switch. { case "colorGUER" : {_marks = _marks + [_x]}; case "colorGREY" : {_marks = _marks + [_x]}; case "colorRED" : {_marks = _marks + [_x]}; }; } foreach allmapmarkers; _nearest = [_marks, player] call BIS_fnc_nearestPosition; If i swap out for the multiple IF statements (which i hate doing) then this below works fine and also gives the nearest marker. // if (markercolor _markers == "colorGUER") then // { // _marks = _marks + [_x]; // }; // if (markercolor _markers == "colorGREY") then // { // _marks = _marks + [_x]; // }; // if (markercolor _markers == "colorRED") then // { // _marks = _marks + [_x]; // }; Any help welcome. Cheers. Share this post Link to post Share on other sites
wogz187 1086 Posted October 12, 2019 @Ramsen III, Try system chatting "_marker" to determine what it actually returns at each stage. systemChat format ["%1", _marker]; have fun! Share this post Link to post Share on other sites
Grumpy Old Man 3549 Posted October 12, 2019 No need to use switch or if statements, you also don't need to use + or pushback to add elements to an empty array if all you want is to filter an already existing array for certain criteria. The select command is your friend: _allowedColors = ["colorgrey","colorred","colorguer"];//important to type these all in lowercase for the check to work _filteredMarkers = allmapmarkers select {toLower getMarkerColor _x in _allowedColors}; When checking for strings it's important to put both strings into the same case, I'm sure that's one reason your check is failing, since the markers color could be defined as "colorRed", so checking for "colorRED" will fail since string comparison is case sensitive. 4 hours ago, wogz187 said: @Ramsen III, Try system chatting "_marker" to determine what it actually returns at each stage. systemChat format ["%1", _marker]; have fun! In that case a simple systemChat will do, no need for format, since markers and marker colors are already supposed to be strings and will throw an appropriate error message if something went wrong. Cheers 1 1 Share this post Link to post Share on other sites
killzone_kid 1333 Posted October 12, 2019 switch is case sensitive, this means the color name should match exactly, so "ColorRed" is not gonna match "colorRED", but == is not case sensitive also _marks = _marks + [_x] => _marks pushBack _x 3 Share this post Link to post Share on other sites
Ramsen III 0 Posted October 12, 2019 Thx for replies. @Grumpy Old Man' cheers bro. first i wanted to eliminate the IF statements so I thought SWITCH would be better.... but of course theres always a better way! + havenot tried your script yet but will figure it out a bit latter. thx @wogz187' funnily enough i already used systemchat to do almost exactly what you said but using _count to count which colored markers it was finding.. but of course it was none! @killzone_kid' yeah grumpy mentioned that too, i did not know it was case senstive. :-/ anyway thx all. p.s Poxy captchas! just asked me to click the 'fire hydrants' and there aint any in the damn picture!?? Honestly my internet banking is easier to access than this site. Share this post Link to post Share on other sites
pierremgi 4909 Posted October 12, 2019 if you don't want to bother you with case sensitive switch do, there is a similar coding: call { if somethingTrue exitWith {fisrt Option Code}; if somethingElseTrue exiwith {secon dOption Code}; if .... exitwith ....; in Case Of: Default Code; }; Here exitwith just exit out of the call. There is a difference with switch do process, for default block, but imho this method is clearer. 1 Share this post Link to post Share on other sites
Dedmen 2721 Posted October 14, 2019 On 10/12/2019 at 4:52 PM, Ramsen III said: Honestly my internet banking is easier to access than this site. And somehow the spambots still get through all of that multiple times per day... (sorry offtopic 😄 everything needing to be said has already been said) Share this post Link to post Share on other sites