ID:269268
 
I'm learning to program, and I don't understand the switch statement. I mean I under stand switch(input, but not like switch in the middle of a proc. So when, and where I it appropriate to use switch?
you use the switch statment in several cases

switch(alert
switch(input
Switch.

Basically you want to use switch when you've got a lot of possible outcomes for a paritcular statement.
Ie, if the player just selected their class and you want to give each class a different icon, stats, etc.
In response to Jay1
Here is a little sample verb...

mob
verb
VerbName()
var/choice = input("Yes or no?","Pick.")in list("Yes","No")
switch(choice)
if("Yes")
switch(input("Are you sure?","Pick.")in list("Yes","No"))
if("Yes")
switch(alert(usr,"You chose yes.","Choice","Ok"))
if("Ok")
return
if("No")
switch(alert(usr,"You changed your mind...","Choice","Ok"))
if("Ok")
return
if("No")
switch(input("Are you sure?","Pick.")in list("Yes","No"))
if("Yes")
switch(alert(usr,"You chose no.","Choice","Ok"))
if("Ok")
return
if("No")
switch(alert(usr,"You changed your mind...","Choice","Ok"))
if("Ok")
return

This should be right.

In response to XxDragonFlarexX
While that would work, it's definantly not the greatest use of switch statements.
For example, you aren't giving the player any choice in a lot of those alerts, so it's pointless to do an if statement of any sort.
For example, instead of putting:
                            switch(alert(usr,"You changed your mind...","Choice","Ok"))
if("Ok")
return

You could put:
alert(usr,"You changed your mind...","Choice","Ok")
return


My sisters house just got broke into, so I'll have to cut this short for now.