SphereCommunity
DOSWITCH - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: DOSWITCH (/Thread-DOSWITCH)



DOSWITCH - pointhz - 05-30-2016 08:21 AM

Just a question I cant figure out myself and couldnt find in the wiki.

How can I use the DOSWITCH function?

Thanks in advance


RE: DOSWITCH - Vaikin - 05-30-2016 08:58 AM

Theres an example in the wiki, should be pretty clear.

Code:
ON=@TargOn_Ground

    POINT_INFO <ARGO.P>
    SRC.SYSMESSAGE The point you targetted was: <VAR.TI_P>
    DOSWITCH <VAR.TI_LOS>

        SRC.SYSMESSAGE The point is not in your line of sight.
        SRC.SYSMESSAGE The point is in your line of sight.

    ENDDO
    SRC.SYSMESSAGE The distance between you and that point is <EVAL <VAR.TI_DISTANCE>> tiles.
    RETURN 1



RE: DOSWITCH - Coruja - 05-30-2016 04:19 PM

DOSWITCH is like an switch to select an specific pre-defined line on the code
Code:
DOSWITCH 3
  SYSMESSAGE Message 0
  SYSMESSAGE Message 1
  SYSMESSAGE Message 2
  SYSMESSAGE Message 3
  SYSMESSAGE Message 4
ENDDO
this will make the code return "SYSMESSAGE Message 3"

of course it doesn't make sense use an fixed switch like this example, because if we always want the line 3, it makes more sense use directly "SYSMESSAGE Message 3" instead an useless DOSWITCH with many results but always returning the same fixed result 3

so DOSWITCH is usefull on situations where you already have some pre-defined lines and want trigger the correct line based on some other value, like this:
Code:
DOSWITCH <DIR> //this return an 0-7 value based on the direction your char is facing
  SYSMESSAGE You are facing N
  SYSMESSAGE You are facing NE
  SYSMESSAGE You are facing E
  SYSMESSAGE You are facing SE
  SYSMESSAGE You are facing S
  SYSMESSAGE You are facing SW
  SYSMESSAGE You are facing W
  SYSMESSAGE You are facing NW
ENDDO

in other words, DOSWITCH does the same thing as this code below but using an clean/optimized code
Code:
IF (<DIR>==0)
  SYSMESSAGE You are facing N
ELIF (<DIR>==1)
  SYSMESSAGE You are facing NE
ELIF (<DIR>==2)
  SYSMESSAGE You are facing E
ELIF (<DIR>==3)
  SYSMESSAGE You are facing SE
ELIF (<DIR>==4)
  SYSMESSAGE You are facing S
ELIF (<DIR>==5)
  SYSMESSAGE You are facing SW
ELIF (<DIR>==6)
  SYSMESSAGE You are facing W
ELIF (<DIR>==7)
  SYSMESSAGE You are facing NW
ENDIF



RE: DOSWITCH - pointhz - 05-31-2016 05:29 AM

Thanks a lot Coruja Big Grin Pretty much clear now xD

Thanks for your answer too Vaikin. I'd seen that example already but couldnt figure out how the DOSWITCH function was picking the SYSMESSAGE xD

If I look at the wiki example now I can figure it out. CanSeeLos returns either 0 or 1 and then it will pick either the first line or the second in the DOSWTICH. Makes sense, but it's not easy to find out unless you think about DOSWITCH picking a line by their order based on numbers.