ID:1089379
 
(See the best response by Jemai1.)
Code:
mob
Bobthebuilder
Login()


Question:
When you load a savefile, how do you make it where you load a mob datum.

Example Above
var/savefile/File = new("something.sav")

mob/Read(File)
//load the file

var {saved_x; saved_y; saved_z}
//load coordinates from the file (must exist already)
File >> saved_x
File >> saved_y
File >> saved_z

//restore variables
..()

//restore coordinates
Move(locate(saved_x,saved_y,saved_z))
No no no, I mean how do you make it, where it sends src, to the datum Bobthebuilder ?
hmmm that? :

Bobthebuilder/Login()
var/savefile/File = new(ckey)
Read(File)
return ..()
Hmm, it's similar to this.
Going from 1 mob datum, to the Load() then making that go to Bobthebuilder datum

Best response
There are different ways to do so.

I usually handle saving/loading with something like this
client
proc
Save()
var/savefile/F = new(SavePath())
F["mob"] << mob
return 1

Load()
var/savepath = SavePath()
if(fexists(savepath))
var/savefile/F = new(savepath)
F["mob"] >> mob
return 1
return 0

SavePath()
return "Saves/[ckey].sav"


Here's a simple example of using that
world
mob = /mob/new_arrival

mob
new_arrival
verb
Load_Character()
if(!client.Load())
src << "Load failed"

New_Character()
client.mob = new/mob/player

player
verb
Save()
client.Save()

When the code runs new_arrival, and they click Load_Character, how do I get it to run a Player/Login()?
F["mob"] >> mob // this line loads the saved mob and sets it as your new mob

Setting the client's mob automatically calls the new mob's Login() proc.
The Login() proc?
mob
player
Login()
world << "[src] joined the game."
..()
Okay, here is some of my code, that could give an idea, what I'm trying to do.

When you create character, and they pick fire, they go to the FirePlayer datum Login(). When they are (del) it saves, and when they load a character, it auto goes to the datum that they were previously in. //Doesn't do the auto part

if(Picknation=="Fire")
if(usr.client)
//src.world.mob=/mob/FirePlayer
F.icon='Base(Black).dmi'
F.icon_state=""
usr.creating=1
F.name=name
F.class="FirePlayer"
usr.notloggedin=0
//F.SaveMob()
var/savefile/N=new("Players/[ckey].sav")
Write(N)
F.client=client
else
return

mob
// FireNation
FireBender
Login()
if(usr.client)
FireBender+=src
src<<"<font color=red><font face=Times New Roman>You learn to bend <i>fire</i>, by opening and closing chi pathways that run throughtout your body!"
src<<"<font color=red><b>Macros: Attack - A, Rest - R"
usr.notloggedin=0
src.Addallverbs()
src.SaveMob()
else
return
..()

proc/Load()
if(fexists("Players/[ckey].sav"))
var/savefile/N=new("Players/[ckey].sav")
Read(N)
var/last_x
var/last_y
var/last_z
N["Last_x"] >> last_x
N["Last_y"] >> last_y
N["Last_z"] >> last_z
N["class"]>>class
//N["mob"] >> mob
Move(locate(last_x,last_y,last_z))
src<<"<font color=red>Character [name] loaded."
else
usr<<"<font color=red>No savefile found."
return


In response to Spritzer
Spritzer wrote:
            var/savefile/N=new("Players/[ckey].sav")
Write(N)
F.client=client


You should not save your "character creator".
Okay, do you know how to make it do what I want it to do?
You can do it the way I did. You just have to modify the New_Character verb.