Jump to content
Ramsen III

Switch code with no result?

Recommended Posts

Hi all. Why does this switch code not work (No error just no/zero result) it should result in the 25 markers.

 

  1. _marks = [];
  2.     {
  3.     _markers = _x;
  4.     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.
  5.         {
  6.         case "colorGUER"    : {_marks = _marks + [_x]};
  7.         case "colorGREY"    : {_marks = _marks + [_x]};
  8.         case "colorRED"    : {_marks = _marks + [_x]};
  9.         };
  10.     } foreach allmapmarkers;
  11. _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.

 

  1. //    if (markercolor _markers == "colorGUER") then
  2. //        {
  3. //        _marks = _marks + [_x];
  4. //        };
  5. //    if (markercolor _markers == "colorGREY") then
  6. //        {
  7. //        _marks = _marks + [_x];
  8. //        };
  9. //    if (markercolor _markers == "colorRED") then
  10. //        {
  11. //        _marks = _marks + [_x];
  12. //        };

 

Any help welcome.

 

Cheers.

Share this post


Link to post
Share on other sites

@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

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

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

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

  • Like 3

Share this post


Link to post
Share on other sites

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

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.

 

  • Like 1

Share this post


Link to post
Share on other sites
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×