The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DOSWITCH
Author Message
pointhz
Journeyman
*

Posts: 148
Likes Given: 1
Likes Received: 55 in 28 posts
Joined: Oct 2013
Reputation: 1



Post: #1
DOSWITCH
Just a question I cant figure out myself and couldnt find in the wiki.

How can I use the DOSWITCH function?

Thanks in advance
(This post was last modified: 05-30-2016 08:21 AM by pointhz.)
05-30-2016 08:21 AM
Find all posts by this user Like Post Quote this message in a reply
Vaikin
Apprentice
*

Posts: 4
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: May 2016
Reputation: 0



Post: #2
RE: DOSWITCH
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
05-30-2016 08:58 AM
Find all posts by this user Like Post Quote this message in a reply
Coruja
Sphere Developer
*****

Posts: 987
Likes Given: 5
Likes Received: 226 in 187 posts
Joined: Jul 2012
Reputation: 7

Dimension Shard

Post: #3
RE: DOSWITCH
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
(This post was last modified: 05-31-2016 07:53 AM by Coruja.)
05-30-2016 04:19 PM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes Coruja's post
pointhz
Journeyman
*

Posts: 148
Likes Given: 1
Likes Received: 55 in 28 posts
Joined: Oct 2013
Reputation: 1



Post: #4
RE: DOSWITCH
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.
(This post was last modified: 05-31-2016 05:31 AM by pointhz.)
05-31-2016 05:29 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)