ID:261844
 
mob/verb/Save()
src.client.SaveMob()
client/proc/SaveMob()
if(src == null)
return 0
var/savefile/F = new("players/[key].save")
var/char_ckey = cKey(src.mob.name)
F["/[ckey]/[char_ckey]"] << src.mob
client/proc/LoadMob(char_ckey)
var/mob/new_mob
var/savefile/F = new("players/[key].save")
F["/[ckey]/[char_ckey]"] >> new_mob
if (!new_mob)
return 0
else
src.mob = new_mob
return 1

mob
Login()
src.loc=locate(1,1,1)
src.sight=1
switch(input("What do you want to do?")in list("Create new character", "Continue", "Quit"))
if("Quit")
del(usr)
if("Create new character")
src.Menu()
if("Continue")
client.LoadMob()
mob/proc/Menu()
var/charname=input("Name","First-Time-User",src.key) as null|text
src.name=charname
switch(input("What Is Your Race [src.name]?","Race") in list ("Saiyan","Human","Namek"))
if ("Saiyan")
icon = 'Saiyan.dmi'
max = 250
race = "Saiyan"
sight=0
if ("Human")
icon = 'Human.dmi'
max = 250
race = "Human"
sight=0
if ("Namek")
icon = 'Namek.dmi'
max = 250
race = "Namek"
sight=0
mob/Human
icon = 'Human.dmi'
max = 250
race = "Human"
mob/Namek
icon = 'Namek.dmi'
max = 250
race = "Namek"
mob/Saiyan
icon = 'Saiyan.dmi'
max = 250
race = "Saiyan"
mob/Logout()
src.Save()
del(usr)

Ok this is what code i have so far, i compile it with no errors, my save verb is working (well i think it is because its creating the save file) but then when i try to load......nothing happends just a black screen im so confused :S oh yeh and thanks fireking for the save code ive got so far</<>
hey hell gate

there is a snippet i forgot to include
you have a blank screen cuz your xyz = null

you can either write your own code to save the xyz and set the mob's loc to that location on login, or use this...

mob
        Write(savefile/F)
                ..()
                F["last_x"] << x
                F["last_y"] << y
                F["last_z"] << z
        Read(savefile/F)
                ..()
                var/last_x
                var/last_y
                var/last_z
                F["last_x"] >> last_x
                F["last_y"] >> last_y
                F["last_z"] >> last_z
                loc = locate(last_x, last_y, last_z)


looks weird, but its called automatically from savemob/loadmob cuz this redefines what Read and Write do for all mobs in the world, so be careful

also, your mob must have these added variables

mob
    var
        last_x
        last_y
        last_z
In response to FIREking
I tried out your svaing and loading stuff, which isn't too shabby. But I too, get a black screen when I click continue. Also, if I am already in the game, and I click the bookmark, to kinda reboot it I get the error:

runtime error: Cannot execute null.SaveMob().
verb name: Save (/mob/verb/Save)
usr: Gokuss4neo (/mob/Player)
src: Gokuss4neo (/mob/Player)
call stack:
Gokuss4neo (/mob/Player): Save()
Gokuss4neo (/mob/Player): Logout()
Connection closed.
Connecting to file://C:\Program Files\BYOND\bin\Dolores Vindicta\Dolores Vindicta.dmb.

~GokuSS4Neo~
In response to Gokuss4neo
Gokuss4neo wrote:
I tried out your svaing and loading stuff, which isn't too shabby. But I too, get a black screen when I click continue. Also, if I am already in the game, and I click the bookmark, to kinda reboot it I get the error:

runtime error: Cannot execute null.SaveMob().
verb name: Save (/mob/verb/Save)
usr: Gokuss4neo (/mob/Player)
src: Gokuss4neo (/mob/Player)
call stack:
Gokuss4neo (/mob/Player): Save()
Gokuss4neo (/mob/Player): Logout()

Simple. You're trying to call client.SaveMob() after src.client has become null. You can't count on src.client to still exist in Logout(). You have to handle this instead in client/Del().

Lummox JR
Hellgate_uk wrote:
mob/verb/Save()
src.client.SaveMob()
mob/Logout()
src.Save()
del(usr)

Two basic problems here.

First, in mob/Logout(), src.client is null. You should really be handling this in client/Del(), or else you should leave src.client out of it completely and let the mob handle its saving. (You don't need the client, as long as you keep track of the key in another var.)

Second, usr is not safe in Logout(). That should be src.

Lummox JR
In response to Lummox JR
Do you know the reason for the Black Screen though? It is really annoying to have to make a new character every time!

~GokuSS4Neo~
In response to Gokuss4neo
Gokuss4neo wrote:
Do you know the reason for the Black Screen though? It is really annoying to have to make a new character every time!

Your character's location isn't being saved and reloaded.

Lummox JR
In response to Lummox JR
But I am SURE that it is.
:
mob
Write(savefile/F)
..()
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z
Read(savefile/F)
..()
var/last_x
var/last_y
var/last_z
F["last_x"] >> last_x
F["last_y"] >> last_y
F["last_z"] >> last_z
loc = locate(last_x, last_y, last_z)


?

~GokuSS4Neo~
In response to Gokuss4neo
Hrm. Then at a guess, I'd say that because you chose to save your character at logout, the key didn't save with it. If you keep track of that in another var and then set it manually at the end of Read(), you should connect to that mob automatically.

Lummox JR
In response to Lummox JR
I am not very...at all familiar with the process of saving/writing, so if you could (very kindly :D) direct me to a post/demo/lib I would be very grateful. Or even better tell me how to manually set the character key.

Thank you VERY much.

~GokuSS4Neo~

P.s. You are great, truly great
I tried this system and even when you have the Save() part under client/Del() it still gives you a black screen after creation.
In response to Delita12345
nevermind I got it to work. The problem is that you need ..() right after the Login code line, and set src.visible = 0 or something like that. however, when you relog and load, the mob is not there (visible?)
I'm equally interested in this thread and would like to have these bugs fixed, as I plan to use this savefile system as a resource for future reference. (If no one has any objections that is.)
In response to Lummox JR
Just incase anyone wants my code, or thinks that they could help me with my code it is :

world/mob = /mob/Player  //This makes the default mob to login to a PC.
mob/New()
src.sight = 0
mob/verb/Save()
src.client.SaveMob()
client/proc/SaveMob()
if(src == null)
return 0
var/savefile/F = new("Players/[key].save")
var/char_ckey = cKey(src.mob.name)
F["/[ckey]/[char_ckey]"] << src.mob
src<<"You have saved!"
client/proc/LoadMob(char_ckey)
var/mob/Player
var/savefile/F = new("Players/[key].save")
F["/[ckey]/[char_ckey]"] >> Player
if (!Player)
return 0
else
src.mob = Player
return 1

mob
Login()
switch(input("What do you want to do?")in list("Create new character", "Continue", "Quit"))
if("Quit")
del(usr)
if("Create new character")
src.Menu()
if("Continue")
client.LoadMob()
mob/proc/Menu()
var/charname=input("Name","First Time User",src.key) as null|text
src.name=charname
src.loc = locate(5,5,1)
src.sight = 0
Age(src)

mob/Logout()
del(src)

mob
Write(savefile/F)
..()
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z
Read(savefile/F)
F["last_x"] >> last_x
F["last_y"] >> last_y
F["last_z"] >> last_z
loc = locate(last_x, last_y, last_z)
..()


~GokuSS4Neo~