ID:146593
 
Code:
client
proc
LoadChar()
var/savefile/S = new("Saves/Player/[src.ckey]")
S["mob"] >> src.mob
S["x"] >> src.mob.x
S["y"] >> src.mob.y
S["z"] >> src.mob.z

SaveChar()
var/savefile/S = new ("Saves/Player/[src.ckey]")
S["mob"] << src.mob
S["x"] << src.mob.x
S["y"] << src.mob.y
S["z"] << src.mob.z

mob/pc
Login()

src.Choose_Char()
..()
proc
Choose_Char()
var/list/char_menu = newlist()
var/Create = "Create New Character"
var/Load = "Load Character"
var/Quit = "Exit"
if(fexists("Player/[src.client.ckey]"))
char_menu.Add(Create,Load,Quit)
var/choice = input("What do you want to do?","Welcome back to [world.name]") in char_menu

if(choice == Create)
switch(alert("Creating a New Character will delete your existing character. Continue?","Warning","Yes","No"))
if("Yes")
Create_Char()
return
if("No")
Choose_Char()
return
if(choice == Load)
src.client.LoadChar()
return
if(choice == Quit)
del(src)
else
char_menu.Add(Create,Quit)
var/choice = input("What do you want to do?","Welcome to [world.name]!") in char_menu

if(choice == Create)
Create_Char()
return
if(choice == Load)
del(src)


Create_Char()
var/mob/mob_created
var/world_name = "[world.name]"
var/value = key
mob_created = new/mob/pc()
mob_created.loc = locate(1,1,1)
src.client.mob = mob_created


Problem description:

Every time I run this I get annoying errors, the first of which being that the create new char window keeps reappearing after you select what option you want, I think something's calling it again and again.

Second, I keep getting error messages about src (/mob/pc) not having a client.

It just doesn't work in general. If anyone can give me a better way of saving a mob I'd appreciate it. (btw: I've read deadron's tutorial, I'm just crap at save files)
i'm not sure about this but usualy save files end with .sav when people wrote save game codes
u have
var/savefile/S = new("Saves/Player/[src.ckey]")


try

var/savefile/S = new("Saves/Player/[src.ckey].sav")
In response to ElderKain
ElderKain wrote:
try

> var/savefile/S = new("Saves/Player/[src.ckey].sav")
>
>


no joy, it's still doing the same thing. It keeps telling me that src.client is null, and then bringing up the dialogue box for creating a new character again (as though the save file doesn't exist)

runtime error: Cannot read null.ckey
proc name: Login (/mob/pc/Login)
usr: Fartmonger (/mob/pc)
src: Fartmonger (/mob/pc)
call stack:
Fartmonger (/mob/pc): Login()

That's the error that comes up whenever you try and create a file.
When you set a client's mob variable that mob's Login() proc is called. When a player chooses to create a new character, you create a new /mob/pc, then mob/pc/Login() is called, which calls Choose_Char() again. =)

You can solve this problem in a number of ways, do all your saving and loading from the client, set a temporary (wouldn't want to save it) flag variable on the new mob that says it's been loaded, or make a new sub-type of /mob to do all of your saving and loading, to name a few. =)
In response to YMIHere
Ah I see what you mean, thanks! I'll probably go for the second method and use /mob/loading or something to call the client load proc thingy.