ID:139860
 
Code:
        Load2()
var/savefile/load
var/last_x
var/last_y
var/last_z
var/HK
//var/HK
load = new ("Player Saves/[mob.ckey]/Save File [mob.savefile].sav")
load["mob"] >> src.mob
load["last_x"] >> last_x
load["last_y"] >> last_y
load["last_z"] >> last_z
load["last_Jutsus"] >> src.mob.Jutsus
src<<"Account loaded. [src.mob], [last_x], [last_y], [last_z]"
world<<"<b>Login Info:</b> [src.mob] has logged in!"
src.mob.loc=locate(last_x,last_y,last_z)
new/HK/Hotkey1(src.mob.client)
new/HK/Hotkey2(src.mob.client)
new/HK/Hotkey3(src.mob.client)
new/HK/Hotkey4(src.mob.client)
new/HK/Hotkey5(src.mob.client)
new/HK/Hotkey6(src.mob.client)
new/HK/Hotkey7(src.mob.client)
new/HK/Hotkey8(src.mob.client)
new/HK/Hotkey9(src.mob.client)
new/HK/Hotkey0(src.mob.client)
for(var/HK/H in src.mob.client.screen)
load["[H]K"] >> HK
if(H)
H.skill= HK
H.overlays+=HK
src.mob.Inventory+=new/obj/Clothing/Head/HeadbandIcon
src.mob.Refresh()
src.mob.Update()
src.mob.ChakraRegen=10


Save()
if(!src)return
if(!src.mob)return

if(src.mob.savefile>=1&&src.mob.savefile<=3)
var/savefile/save
save = new ("Player Saves/[mob.ckey]/Save File [mob.savefile].sav")
save["mob"] << src.mob
save["last_x"] << src.mob.x
save["last_y"] << src.mob.y
save["last_z"] << src.mob.z
save["last_Jutsus"] << src.mob.Jutsus
for(var/HK/H in src.mob.client.screen)
if(H.skill)
save["[H]K"] << H.skill
//src.mob<<"Saved [H.skill] to [H]!"
src<<"Successfully saved to <b>slot [mob.savefile]</b>"


Problem description: Recently out of nowhere the save system just became corrupt, like it would tell me I've saved and it would save and load hotkeys and coordinates but for some reason it isn't saving and loading variables.. I don't understand why this is happening.. any ideas?

You should not be writing anything to the savefile except the mob itself. Anything else that needs to be done to save the mob properly needs to go in mob/Write() and mob/Read().

Most likely the issue is that the old mob is sticking around and screwing things up in some manner when you load. Seeing an ExportText() of the savefile would be helpful.

Also, src.mob.client is amusing to me.
In response to Garthor
Garthor wrote:
You should not be writing anything to the savefile except the mob itself. Anything else that needs to be done to save the mob properly needs to go in mob/Write() and mob/Read().

Most likely the issue is that the old mob is sticking around and screwing things up in some manner when you load. Seeing an ExportText() of the savefile would be helpful.

Also, src.mob.client is amusing to me.

Is there a better way than src.mob.client? src gives me errors. and here's what I got from exportext():

abdeljn = object(".0")
.0
type = /mob
clienteye = object("..")
hair_color = "#d4c513"
headband_color = "#5f5f5f"
_Cooldowns = list("Shadow Clone" = 823444)
move_delay = 3
Level = 12
MEXP = 155
Stamina = 83
Chakra = 128
MC = 128
Wounds = 40
Strength = 35
MSTR = 35
Mind = 20
Defense = 36
MDEF = 36
Agility = 40
MA = 40
SP = 1100
StatPoints = 0
Hair = object(".0")
.0
type = /icon
icon = filedata("name=;ext=.dmi;length=6869;crc32=0x655cbac5;encoding=base64",{"
iVBORw0KGgoAAAANSUhEUgAAAeAAAAHACAMAAABNpkuRAAAAjVBMVEX//9P//9P//9P//9PUxRP/(LOTS of random letters)
Base = filedata("name=Base.dmi;length=59406;crc32=0x3815fe85;encoding=base64",{"More random letters"}
)

Nonclan = 1
Control = 30
EXP = 85
Weight = 0
Village = "Leaf"
Clan = "Chakra"
savefile = 1
Jutsus = list(object(".0"),object(".1"),object(".2"),object(".3"),object(".4"),object(".5"),object(".6"))
.0
type = /Jutsus/GatherChakraIcon
Grabbed = list()
mouse_drag_pointer = appearance(filedata("name=;ext=.dmi;length=1941;crc32=0x6b0465ad;encoding=base64",{"More random letters"})

.8
type = /obj/Clothing/Head/HeadbandIcon
Grabbed = list()
Equipped = list()
pieces = list()
obtainedskills = list()
Learned_Skills = list()
oldoverlays = null
Grabbed = list()
name = "Orange Hokage"
icon = object("../Base",0)
icon_state = ""
overlays = list(appearance(object("../Hair/.0/icon",0)),appearance(object("../Head",0)))
dir = 8
gender = "male"
key = "AbdelJN"


Thats most of the readable information.. Ughh I find saving and loading one of the most complicated things to program on BYOND.. I'm sorry bout not knowing how to do this.


In response to AbdelJN
Well I just replaced the save system.. this one seems more efficient but I'm getting a couple of problems..

client
proc
Load()
var/savefile/F = new("Player Saves/[usr.client.ckey]/[usr.savefile].sav")
usr.Read(F)
return
mob
Write(savefile/F)
..()
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z
sleep(2)
for(var/HK/H in src.client.screen)
if(H&&H.skill)
F["[H]K"] << H.skill

Read(savefile/F)
if(savefile!=null||savefile!=0)
..()
var/last_x
var/last_y
var/last_z
var/HK
new/HK/Hotkey1(src.client)
new/HK/Hotkey2(src.client)
new/HK/Hotkey3(src.client)
new/HK/Hotkey4(src.client)
new/HK/Hotkey5(src.client)
new/HK/Hotkey6(src.client)
new/HK/Hotkey7(src.client)
new/HK/Hotkey8(src.client)
new/HK/Hotkey9(src.client)
new/HK/Hotkey0(src.client)
F["last_x"] >> last_x
F["last_y"] >> last_y
F["last_z"] >> last_z
for(var/HK/H in src.client.screen)
F["[H]K"] >> HK
if(H)
H.skill= HK
H.overlays+=HK
var/destination = locate(last_x, last_y, last_z)

if (!Move(destination))
loc = destination
for(var/mob/M in oview(0,src))
if(!M.client&&M.name==src.name)
del(M)
src.Update()
src.Refresh()
src.BuildIcon()
return
mob
verb
Save()
src<<"Character Saved!"
var/savefile/F = new("Player Saves/[src.client.ckey]/[src.savefile].sav")
src.Write(F)


1. I get this runtime error whenever I login.

runtime error: BYOND Error: bad mob
proc name: Read (/mob/Read)
source file: Save2.dm,32
usr: null
src:
call stack:
Read(Player Saves/abdeljn/1.sav (/savefile))
AbdelJN (/client): Load()
LOAD (/obj/LOAD): Click(the turf (41,40,2) (/turf), "default.map1", "icon-x=19;icon-y=25;left=1;scr...")


This happens on this line:

    Read(savefile/F)
..()//this line...


Also the second problem is that either the skills aren't saving to the hotkeys or they aren't loading.. I have a feeling it's related to the first problem.. and ideas?
In response to AbdelJN
Calling Read() and Write() directly is going to result in corrupted savefiles. What you had originally is the proper way to save, and your savefiles won't be compatible between the two methods (and may possibly result in the error you are getting, I dunno and it's not really important).

Additionally, you should not be using usr in procs. Especially if you are doing something like "usr.client.ckey" from within a client's proc. But ESPECIALLY ever.
In response to AbdelJN
You are attempting to read from the directory "mob" in the savefile. However:

abdeljn = object(".0")


Your mob is saved under the directory "abdeljn". So, attempting to read from "mob" gives you nothing.
In response to Garthor
Alright here is my next attempt.. I feel like I'm getting the hang of it but know the players character isn't being loaded. All that's being loaded are the location, the jutsu, and the hotkeys. I think it's because I'm saving them using the Write() proc.. I haven't saved the mob with the write() proc because you've told me that it isn't right.. do you have an idea of how I'd get the character to load?

client
proc
Load()
var/savefile/F
var/last_x
var/last_y
var/last_z
var/HK
//var/HK
F = new ("Player Saves/[mob.ckey]/Save File [mob.savefile].sav")
F["Player Saves/[mob.ckey]/Save File [mob.savefile].sav"] >> mob
F["last_x"] >> last_x
F["last_y"] >> last_y
F["last_z"] >> last_z
F["last_Jutsus"] >> mob.Jutsus
src<<"Account loaded. [mob], [last_x], [last_y], [last_z]"
world<<"<b>Login Info:</b> [mob] has logged in!"
mob.loc=locate(last_x,last_y,last_z)
new/HK/Hotkey1(mob.client)
new/HK/Hotkey2(mob.client)
new/HK/Hotkey3(mob.client)
new/HK/Hotkey4(mob.client)
new/HK/Hotkey5(mob.client)
new/HK/Hotkey6(mob.client)
new/HK/Hotkey7(mob.client)
new/HK/Hotkey8(mob.client)
new/HK/Hotkey9(mob.client)
new/HK/Hotkey0(mob.client)
for(var/HK/H in mob.client.screen)
F["[H]K"] >> HK
if(H)
H.skill= HK
H.overlays+=HK
mob.Inventory+=new/obj/Clothing/Head/HeadbandIcon
mob.Refresh()
mob.Update()
mob.ChakraRegen=10


Save()
if(!src)return
if(!mob)return

if(mob.savefile>=1&&mob.savefile<=3)
var/savefile/save
save = new ("Player Saves/[mob.ckey]/Save File [mob.savefile].sav")
mob.Write(save)

mob
Write(savefile/F) // Write proc
..()
//var/HK
F["mob"] << src
F["last_x"] << x // saves your x location on the map
F["last_y"] << y // saves your y location on the map
F["last_z"] << z // saves your z location on the map
for(var/HK/H in src.client.screen)
if(H)
F["[H]K"] << H.skill
In response to AbdelJN
            F["Player Saves/[mob.ckey]/Save File [mob.savefile].sav"] >> mob


F["mob"] << src


These still don't match. And you still need to put pretty much the entirety of your Save() and Load() procedures (except for the lines that read and write the mob itself) into mob/Write() and mob/Read().

Reading the Guide on the matter might help.