ID:318940
 
(See the best response by Neimo.)
Code:
mob/verb
Save()
set hidden = 1
if(usr.telalogin==0)
var/savefile/F = new("players/[src.key].sav")
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z
src.X = src.verbs
Write(F)
src << "<small><font color=red><b>Saved!"

else
usr<<"You <b>can't</b> save here"
return

mob
proc
Load()
if(fexists("players/[src.key].sav"))
var/savefile/F= new("players/[src.key].sav")
F["last_x"] >> x
F["last_y"] >> y
F["last_z"] >> z
Read(F)


Problem description:
So, sometimes, when I log in the server, my save have just "gone", and I log like this:
Luan12(Luan12) have logged in the server.
then my verbs, my char, everything is just GONE
the problem describtion didn't give me much information though.
Ok, you have the save right? YOur character, your verbs, your vars saved...
BUT, sometimes in the server, I don't know why god in a beautifull morning you enter in the server and: PÁ, you lose your save! And in the server, when you enter appears this:

YourKey(YourKey) has logged in the server instead
YourName(YourKey) has logged in the server, you know?
First off, you should not be calling Read() and Write() directly, and you are saving incorrectly.

client
proc
Save()
var/savefile/F = new("[ckey].sav")
F["mob"] << mob
// Do not add anything more to be saved here
Load()
if(fexists("[ckey].sav"))
var/savefile/F = new("[ckey].sav")
F["mob"] >> mob
// Do not add anything more to be loaded here

mob
Write(var/savefile/F)
..()
// Add any special processing for saving here
F["x"] << x
F["y"] << y
F["z"] << z
Read(var/savefile/F)
..()
// Add any special processing for loading here
loc = locate(F["x"], F["y"], F["z"])
You can't use F["x"] and such directly. Those need to be loaded into local vars before you use them in locate().

mob/Read(savefile/F)
var X,Y,Z
..()
F["x"] >> X
F["y"] >> Y
F["z"] >> Z
loc = locate(X, Y, Z)

Otherwise though you're quite correct, it's a bad idea to call Read() or Write() directly.
In response to Lummox JR
Why does it work if you're not supposed to?
In response to Lummox JR
What's wrong with using F["X"], F["Y"], and F["Z"] directly as it pulls the data from the savefile? I would assume it's better than creating 3 new variables to load what could be done directly.
In response to Neimo
Which proc I call to save and load?

To Save -> only Save or Save and write? like this:
usr.Write()
usr.client.Save()

To Load -> only Load or Read too? like this:
usr.Read()
usr.client.Load()
Do not call them at all (Read()/Write()), they call themselves automatically.

usr.client.Save() // for saving
usr.client.Load() // for loading
In response to Neimo
With your SAVE System, i create the char, when I relog appears the same bug...

You're in the first screen of the server, your name and your status are just gone...
In response to Neimo
Neimo wrote:
What's wrong with using F["X"], F["Y"], and F["Z"] directly as it pulls the data from the savefile? I would assume it's better than creating 3 new variables to load what could be done directly.

Unless I'm way out of date on this, it can't be done directly; a savefile does not actually work like an associative list, and needs the << and >> operators to function correctly.
In response to Lummox JR
only the read is wrong?
Well what Neimo was saying was that you shouldn't be calling Read() and Write() directly, with which I agree; you should do the location saving/loading inside those routines. The only correction I had was that the way he implemented the Read() won't work. You need to load the x,y,z coords into local vars and then use locate().
In response to Lummox JR
You must be out of date then, you can check for yourself; receiving data directly doing F["x"] is possible.

Luan12 wrote:
With your SAVE System, i create the char, when I relog appears the same bug...

You're in the first screen of the server, your name and your status are just gone...

Have you tried using client/New() and client/Del() for saving and loading? Are you logging in twice? Does it actually create the savefiles?
Yes, I recreated the char. NO, i'm not loggin in twice
In response to Luan12
Yes to what? Show everything that you have dealing with your saving/loading system.
I recreated it. Ok, i'll show:

client
proc
Save()
var/savefile/F = new("players/[ckey].sav")
F["mob"] << mob
// Do not add anything more to be saved here
Load()
if(fexists("player/[ckey].sav"))
var/savefile/F = new("players/[ckey].sav")
F["mob"] >> mob
// Do not add anything more to be loaded here

mob
Write(var/savefile/F)
..()
// Add any special processing for saving here
F["x"] << x
F["y"] << y
F["z"] << z
src.X = src.verbs
Read(var/savefile/F)
..()
// Add any special processing for loading here
loc = locate(F["x"], F["y"], F["z"])
src.verbs = src.X
world<<"Deu certo"

mob/Logout()
src.client.Save()
del src
mob/proc/Choice()
switch(alert("O que você quer fazer?","Char","Criar","Log In","Deletar"))
if("Criar")
src.create()
if("Log In")
if(fexists("players/[src.key].sav"))
src.client.Load()
Best response
I hope you still aren't having any problems and that you can read English pretty well. (from your game's language)

world
mob = /mob/player // path for real mobs

mob/var/tmp/active = 0

mob/Read(var/savefile/f)
..()
loc = locate(f["x"], f["y"], f["z"])
world << "[src] has logged back in."
active = 1 // now you will be able to activate auto-saving

mob/Write(var/savefile/f)
..()
f["x"] << x
f["y"] << y
f["z"] << z
f.dir.Remove("icon", "verbs", "contents", "overlays", "underlays")
// it is ideal to remove all unnecessary data in savefiles that can be reloaded & created
// all icon data and /mob/var/icon variables should be removed from saving

mob/player
Login()
loc = locate(/turf/places/titlescreen) // self explanitory

Logout()
del(src)

client/New()
world << "[src] has logged in!"
chooseoption() // call the action to new/load/delete a game
..()

client/Del()
if(mob && mob.active) // if your mob isn't null & you're logged in
savecharacter() // save your character (auto-saving)

world << "[src] has logged out!"
..()

client/proc
chooseoption(var/option)
do
option = input(src, "Description", "Title") in list ("New", "Load", "Delete")
while(!validoption(option)) // while you cannot choose the option, keep doing it
switch(option)
if("New")
newcharacter()
src << "You have started a new game."
if("Load")
loadcharacter()
src << "You have loaded your game."
if("Delete")
fdel("path/[ckey].sav")
src << "You have deleted your game."

loadcharacter()
var/savefile/f = new("path/[ckey].sav")
f["mob"] >> mob

newcharacter()
// all things pertaining to your new character/game, i don't know it

savecharacter()
var/savefile/f = new("path/[ckey].sav")
f["mob"] << mob

validoption(option)
switch(option)
if("New")
if(fexists("path/[ckey].sav"))
src << "You already have a game saved."
return 0
if("Load")
if(!fexists("path/[ckey].sav"))
src << "You don't have a character to load."
return 0
if("Delete")
if(!fexists("path/[ckey].sav"))
src << "You don't have a character to delete."
return 0
return 1

I just wrote this and did not test anything -- I compile tested -- so if any bugs report let me know.
Another way to go, as a nicer option, is you can look at whether the file exists before presenting the new/load/delete options, and hiding or disabling those that don't apply.
In response to Neimo
Hey man, I put your system, and it happened:

Luan12 has logged off
Luan has logged back in.

So, my view was wrong, my verbs desapeared, and my player was invisible, also I couldn't move.
Page: 1 2