ID:147959
 
I am not sure whether this belongs in newbie central or here. It involves quite complicated stuff-ish, so I figured I should put it here.

Okay! First of all, what is the deal with switches? I have seen hundreds of different uses, and formats of them. Some like : switch(buildinglist) , some like : switch(input("BLERB?", "Shopkeeper",text) in list ("Black Shirt","Red Shirt")). Can someone tell me how to use these properly and efficiently?

Also with the switch(buildinglist) type, they always had something in the ( )'s after the verb bit, e.g. AskShop(e.t.c), is there a way of doing this outside of the ( )'s ?


Now to the saving bit.

I use this :

mob
verb
Save()
var/savefile/F = new(ckey)
Write(F)
usr << "Saved!"
usr.saved = 1
Load()
if(usr.saved)
var/savefile/F = new(ckey)
Read(F)
usr << "Loaded!"
else
usr << "You've never saved, so you can't load!"
usr << "We shall give you a new character!"
sleep(2)
usr << "Initializing"
sleep(1)
usr<<"."
usr.Cash = 700
sleep(2)
usr<<".."
sleep(1)
usr<<"."
sleep(5)
usr.Name = usr.key
usr.loc = locate(2,2,1)
usr<<"Complete!"

Write(savefile/F)
F["last_x"] << x
F["last_y"] << y
F["last_x"] << z
Read(savefile/F)
..() //Defualt of read is to restore the variables
var/last_x
var/last_y
var/last_z
F["last_x"] >> last_x
F["last_y"] >> last_y
F["last_x"] >> last_z
src.loc=locate(last_x,last_y,last_z)


From Airjoes simple saving system, but it has a problem. How can I make it save all of the persons lists and variables? Because at the moment it doesn't!

Thank you!

~GokuSS4Neo~
Thank you for noticing! I forgot to call the ..() on Write().

I'll go fix it now. You can do it yourself for that code.
switch() is basically a glorified if(). Okay, that's not quite true. Actually, it's not true at all. =P But it does make choices based on a condition, like if() does.

Consider this switch():

<code>switch(src.gender) if (MALE) src << "You are male." if (FEMALE) src << "You are female." if (NEUTER) src << "Your gender has not been specified." if (PLURAL) src << "There's lots of you."</code>

This checks src's gender var. If src.gender is equal to MALE, then it tells src "You are male." If src.gender is equal to FEMALE, it tells src "You are female." If src.gender is equal to NEUTER, it tells src "Your gender has not been specified." If src.gender is equal to PLURAL, it tells src "There's lots of you."

That's basically all there is to it. Those "switch(input(...) as ... in ...)" constructions are simply combining input() and switch() statements; all the italics in that example is part of the input(), rather than the switch().
In response to Crispy
But I still have one query. I have seen used, where it says switch(*a var*) and it has brought up something on screen which you can choose, like a imput switch. How can the "building as null|anything in src.buildings_list" bit be done inside the proc/verb so that you could do multiple switch(building), switch(building2). Or would you have to do multiple procs?:
        Build(building as null|anything in src.buildings_list)
switch(building)


~GokuSS4Neo~