ID:146976
 
Here is a saving/loading code that I'm using for a game of mine. It works perfectly except for that you don't appear in the place where you last savd your game. No clue why.

verb
Load_Char()
var/savefile/F = new(ckey)
Read(F)
usr << "Character loaded."
Save_Char()
var/savefile/F = new(ckey)
Write(F)
usr << "Character saved."
Make sure your saving src.x, src.y, and src.z, do this:
Make:
var/lastx = src.x
var/lasty = src.y
var/lastz = src.z
save those variables
load to those variables
at the end of the loading code
type:
src.loc = locate(lastx,lasty,lastz)
In response to Lenox
How would I do that?
In response to Jetz
Here's an example(This is what I use).

        SaveChar(char_name)
var/savefile/F = new("/[src.ckey]/[char_name]/Player.sav")
var/lastx = src.x
var/lasty = src.y
var/lastz = src.z
F["LastX"] << lastx
F["LastY"] << lasty
F["LastZ"] << lastz
F["Inventory"] << src.contents
F["Mob"] << src.client.mob
LoadChar(char_name)
var/savefile/F = new("/[src.ckey]/[char_name]/Player.sav")
var/lastx
var/lasty
var/lastz
F["LastX"] >> lastx
F["LastY"] >> lasty
F["LastZ"] >> lastz
F["Inventory"] >> src.contents
F["Mob"] >> src.client.mob
In response to Lenox
You used
F["Mob"] >> src.client.mob

What's wrong with this? Well, you, as the mob, are pointning to the client, who is pointing straight back at the mob. Instead, use
F["Mob"] >> src

Also, You don't need "Inventory" since mob/list/contents gets saved along with the above line anyway.

Hope this helps :)
In response to Wizkidd0123
Ah, well, you saved me a line and some troubles as well :P Thanks for pointing that out.
In response to Lenox
Now working at all now. Here is my code.

SaveChar()
var/savefile/F = new("/[src.ckey]/[char_name]/Player.sav")
var/lastx = src.x
var/lasty = src.y
var/lastz = src.z
F["LastX"] << lastx
F["LastY"] << lasty
F["LastZ"] << lastz
F["Mob"] << src.client.mob
LoadChar()
var/savefile/F = new("/[src.ckey]/[char_name]/Player.sav")
var/lastx
var/lasty
var/lastz
F["LastX"] >> lastx
F["LastY"] >> lasty
F["LastZ"] >> lastz
F["Mob"] >> src
src.loc = locate(lastx,lasty,lastz)
In response to Jetz
Jetz wrote:
Now working at all now. Here is my code.

SaveChar()
var/savefile/F = new("/[src.ckey]/[char_name]/Player.sav")
var/lastx = src.x
var/lasty = src.y
var/lastz = src.z
F["LastX"] << lastx
F["LastY"] << lasty
F["LastZ"] << lastz
F["Mob"] << src.client.mob
LoadChar()
var/savefile/F = new("/[src.ckey]/[char_name]/Player.sav")
var/lastx
var/lasty
var/lastz
F["LastX"] >> lastx
F["LastY"] >> lasty
F["LastZ"] >> lastz
F["Mob"] >> src
src.loc = locate(lastx,lasty,lastz)

If you mean it DOESNT work, it's because you have to do all that stuff in Write and Read then call them..

mob
verb
Load_Char()
var/savefile/F = new(ckey)
Read(F)
usr << "Character loaded."
Save_Char()
var/savefile/F = new(ckey)
Write(F)
usr << "Character saved."
Write()
var/savefile/F = new("/[src.ckey]/[src.name]/Player.sav")
var/lastx = src.x
var/lasty = src.y
var/lastz = src.z
F["LastX"] << lastx
F["LastY"] << lasty
F["LastZ"] << lastz
F["Mob"] << src
Read()
var/savefile/F = new("/[src.ckey]/[src.name]/Player.sav")
var/lastx
var/lasty
var/lastz
F["LastX"] >> lastx
F["LastY"] >> lasty
F["LastZ"] >> lastz
F["Mob"] >> src
src.loc = locate(lastx,lasty,lastz)

In response to XxDohxX
When I try to save with that, it gives me an error that keeps appearing and Dream Seeker does nothing but show the error, over and over again. It said that it couldn't read the savefile.
In response to Jetz
It can't read a savefile if it hasn't been written yet, is the savefile even there? '-_-
In response to Lenox
I know, it's really weird. But that's what the error said. And the savefile never appeared,