Tutorial for the Select Case True Command

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Tutorial for the Select Case True Command

Postby cpkspikyhair » Mon Jun 22, 2009 8:28 pm

Select Case True Tutorial

The Select Case command in VBScript is usually used to test the value of one variable in a neat, list-like way.

For example:

Code: Select all
Select Case var
     Case 1
           MsgBox "Hello."
     Case 2
           MsgBox "Goodbye."
End Select

It works a lot like the If....ElseIf statements, but it is neater and once you get used to it, it can be easier to debug.

But many people don't know about another way to use Select Case, the Select Case True command.

The Select Case True command tests multiple statements, or "cases", to see if they are true, instead of testing one variable's value. It works in a way that is almost backwards from the original Select Case. It can also test multiple statements at the same time, using the conjunction "And".

For example, this shows a way you can test multiple variables' values:

Code: Select all
Select Case True
     Case (upvar = 1)
           MsgBox "You hit the UP key."
     Case (leftvar = 1)
           MsgBox "You hit the LEFT key."
     Case (downvar = 1)
           MsgBox "You hit the DOWN key."
     Case (rightvar = 1)
           MsgBox "You hit the RIGHT key."
     Case ((upvar = 0) And (leftvar = 0) And (downvar = 0) And (rightvar = 0))
           MsgBox "You did not hit any key."
End Select

Again, it does work very much like using If...ElseIf, but it is neater-looking and more organized, and in my opinion it is easier to keep track of multiple Select Case True statements than a hierarchy of If and ElseIf statements.
PSPPC GameMaker!! Where you can find PSP and PC games up for download!
User avatar
Games Page Administrator
Posts: 425
Joined: Thu Jun 28, 2007 1:49 pm
Location: On Mars (Yes There Is Water :) )

Postby Lyberodoggy » Mon Jun 22, 2009 11:44 pm

Thanks for this one :)
User avatar
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby reneuend » Wed Jun 24, 2009 4:39 pm

Cool Idea, Spike! I hadn't thought of this! :)

User avatar
Posts: 2731
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest