ID:166165
 
I've been looking up how to save player stats when they log out. To do so, I looked at the DM code, and found the code. So my code looks like this:

    Login()
var/savefile/F = new(ckey)
Read(F)

switch(input("Which race would you like to be?") in list ("Human","Elf","Vampire","Lycan","Demon","Angel"))
if("Human")
src.icon = 'human.dmi'
if("Elf")
src.icon = 'elf.dmi'
if("Vampire")
src.icon = 'vampire.dmi'
if("Lycan")
src.icon = 'lycan.dmi'
if("Demon")
src.icon = 'demon.dmi'
if("Angel")
src.icon = 'angel.dmi'

..() //the gender of their key. Then call the parent!
world << "[usr] has entered!"


return ..()

Logout()
world<<"Player [src] has logged out.."
var/savefile/F = new(ckey)
Write(F)
del(src)


As you can see, when a player logs in, they are asked which race they are going to be, which changes their icon appropriately. When they log out, their stats are saved.

However, when they log back in, their stats are loaded, but they are asked which race they want to be again.

How can I make it so that the race they chose will be saved and loaded the next time they enter the world?
a boolean variable.

Do something like this:

mob/var/race=null
mob
Login()
var/savefile/F = new(ckey)
Read(F)
if(!src.race)
switch(input("Which race would you like to be?") in list ("Human","Elf","Vampire","Lycan","Demon","Angel"))
if("Human"){src.race="Human"}
// and so on, then do whatever
else

//send them somewhere
You can use the <code>Read() and Write() functions to accomplish this. May I recommend the DM Guide? I also recommend using sub-types. mob, mob/player, mob/player/human, mob/player/elf, ...