ID:144481
 
Code:
mob/proc/Save()
var/savefile/F = new("players/[src.ckey]")
F["last_x"] << src.x
F["last_y"] << src.y
F["last_z"] << src.z
Write(F)
mob/proc/Load()
if(fexists("players/[src.ckey]"))
var/savefile/F = new("players/[src.ckey]")
Read(F)
F["last_x"] >> src.x
F["last_y"] >> src.y
F["last_z"] >> src.z


mob
Login()
usr.new_char()

mob
proc
new_char()
switch(input("Welcome to Tales of Xenologia!", "New Character")in list("Create new Character", "Load Character"))
if("Create new Character")
usr.race_choose()
if("Load Character")
usr.Load()


mob
proc
race_choose()
switch(input("Welcome to Tales of Xenologia!", "Race?")in list("Lizard-Human", "Human", "Demon"))
if("Lizard-Human")
usr.icon = 'Human White.dmi'
usr.loc = locate(1,1,1)

mob
Logout()
usr.Save()


Problem description:When I load the game, it loads all the vars and things(Such as name) but the screen just goes black. It's just randomly happened to all my games. One day it's working fine, the next it's stuffed. I'm not sure whats wrong with it.

Due to the way BYOND works, you can't individually load x, y, and z, and have the player go to the right place. Instead, make some temporary variables inside your loading procedure (ex temp_x, temp_y, temp_z), and load the x, y, and z coordinates to those variables. Once you've done that, use locate() to set the player to the proper location.
In response to Jon88
I get it, but I don't...Can you show me...?
In response to Strong123488
Jon was talking about making individual variables to make last_x, last_y, and last_z and then setting your loc through them; something like this:
var/tempx,tempy,tempz
F["last_x"]>>tempx
F["last_y"]>>tempy
F["last_z"]>>tempz
loc=locate(tempx,tempy,tempz)

That method works, but this one does it without setting variables and takes less typing:
loc=locate(F["last_x"], F["last_y"], F["last_z"])
In response to Ephraim
Ephraim wrote:
That method works, but this one does it without setting variables and takes less typing:
> loc=locate(F["last_x"], F["last_y"], F["last_z"])
>


Except for the part where it doesn't work at all. The first way you showed, loading individually to tempx/y/z and then using locate(), was correct. This way is not.

A savefile cannot be treated like a regular list the way you're using it here. To get a value out of the file you actually have to use the >> operator, and you absolutely have to use << to save it.

Lummox JR