ID:140313
 
Code:
mob/proc
Savee()
fdel("savefile/[usr.ckey].sav") // deletes the old save file
var/savefile/F=new("savefile/[src.ckey].sav") // creates a new save file
src.Write(F) // writes your variables/lists onto it
F["lastx"] << src.x //saves your x coord
F["lasty"] << src.y //saves your y coord
F["lastz"] << src.z //saves your z coord
Loadd()
if(fexists("savefile/[usr.ckey].sav"))//if an existing save file exists in the folder located in the game folder
var/savefile/F=new("savefile/[src.ckey].sav") // it creates a new save file
src.Read(F) //it reads it
var/newX
var/newY
var/newZ
F["lastx"] >> newX//it takes the lastx variable in the save and puts it into the newx variable
F["lasty"] >> newY//same as above with a new variable
F["lastz"] >> newZ//same as above with a new variable
src.loc=locate(newX,newY,newZ)//makes the player located in those locations
mob/commands
verb
Save()
set category="Chat"
src.Savee()
src << "Game saved!"
//src << "Saving and loading is temporarily disabled due to a major bug. Sorry."


Problem description:
I had a topic like this before, but since then I completly deleted the old code and used this save system above from a different BYOND library instead, this one: http://www.byond.com/developer/Agrey123/SaveLoad but anyways

Saving and loading works for every player in my Ham Ham Rivals game. But, after like an hour of people saving and loading every once in awhile, whenever people save or load, I get an error (I don't have that error on hand but it referred to the save proc when saving and the load proc when loading) and it saves their save file as a 0kb file when saving gives me errors like that.

How can I fix this?

(Oh, and that one method that involves saving/loading the "mob" never works for my game every time I try it, even when I try using BYOND libraries that save/load that way, so yeah :3.)
You shouldn't be using usr in procs.

You shouldn't be calling Read() or Write() directly, as this can cause errors in a savefile. You need to use F << mob (or ideally F["mob"] << mob). If you are having problems with this, then the issue is with how you are doing it, not with the concept as a whole. For an example of how to do it properly, see: [link]

You shouldn't be saving the x,y,z etc. stuff in Savee(). That should be done by overriding mob/Write(). Ditto for loading it (should be in mob/Read()).

If you are getting a runtime error, it's usually pretty important to actually tell us what it is.
client/var/savefile/f
client/proc

setsave(){if(!f){f=new("savefile/[ckey].sav")}}

Savee(){src.setsave();f["player"]<<mob}

Loadd(){src.setsave();if(f.dir.Find["player"]){f["player"]>>mob}}

client/Del(){Savee();..()}

mob/Write(savefile/f){..();f["x"]<<x;f["y"]<<y;f["z"]<<z}
mob/Read(savefile/f){..();loc=locate(f["x"]>>x,f["y"]>>y,f["z"]>>z)}

mob/verb/Save(){client.Savee();src << "Game saved!"}

You shouldn't call the write and read procedure directly. Also it's much easier to check if a savefile exists than continually coping and pasting the same line everywhere. I wrote this on the forum not in dream maker. I will decompact it when I get home. It might have a few errors that need fixing which I will also take care of.
In response to Garthor
You beat me to it, darn my sidekick's non-3Gness.
In response to Garthor
I implemented the main stuff in the post you linked to, but when the game loads, it reboots me into the game with me still at the title screen and gives me this error:

runtime error: Cannot read null.loc
proc name: Center (/client/Center)
source file: Center.dm,358
usr: null
src: MartialArtistAbu (/client)
call stack:
MartialArtistAbu (/client): Center()

I forgot to mention, but loading happens in client/Center() since it happens when the user uses center as an arrow icon when the user's location is next to a graphic that says Continue (hard to explain in words but yeah)

so loading is like this:

client
Center()
if(usr.loc == locate(1,5,18)) //it says "src.loc: undefined var" when I use src here
if(fexists("[key].save"))
var/savefile/F = new("[key].save")
F["mob"] >> mob


and everything else is like this:

mob/Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
mob/Read(var/savefile/F)
..()
var/turf/T = locate(F["x"], F["y"], F["z"])
if(T)
loc = T
client/proc
Savee()
var/savefile/F = new("[key].save")
F["mob"] << mob
Loadd()
if(fexists("[key].save"))
var/savefile/F = new("[key].save")
F["mob"] >> mob


but when I use Center on the title screen of the game next to the Continue graphic to load, it once again just restarts the game, and also removes a bunch of my verbs and makes this one form thing not able to work for me and gives me that one runtime error and yeah :X
In response to MartialArtistAbu
This would be a result of you having code mucked up elsewhere. Most likely, you are using mob/Logout() to handle players disconnecting. This is wrong. Use client/Del() instead.

Similarly, mob/Login() is not when a player connects, client/New() is.
In response to Garthor
Okay, I rewrote mob/Logout() to use client/Del() instead and mob/Login() to use client/New() instead.

Anyways, now how do I call Savee() in a verb that saves the game? (edit: actually I fixed it and have a different question below but yeah)

I tried

mob/commands
verb
Save_Game()
set category="Chat"
if(usr.fused == 1)
src << "You can't save while fused. Defuse and then save."
else
client.Savee() //src.client.Savee() gives me the same runtime error
src << "Game saved!"


but I get this runtime error:

runtime error: undefined variable /client/var/client
proc name: Save Game (/mob/commands/verb/Save_Game)
source file: Commands.dm,1488
usr: MartialArtistAbu the Ham-Ham (/mob)
src: MartialArtistAbu (/client)
call stack:
MartialArtistAbu (/client): Save Game()


Also, I used usr.fused (it's one of my atom/movable variables in my game) instead of src.fused because when I use src.fused, I get this runtime error:

runtime error: undefined variable /client/var/fused
proc name: Save Game (/mob/commands/verb/Save_Game)
source file: Commands.dm,1485
usr: MartialArtistAbu the Ham-Ham (/mob)
src: MartialArtistAbu (/client)
call stack:
MartialArtistAbu (/client): Save Game()


also I dunno if it's normal, but when I changed mob/Login() to client/New() I had to change each variable assignment to src.mob instead of just src alone since src alone tells me "undefined var" whenever I compile. Just mentioning that in case it's not normal, but yeah.

Well anyways, how do I go about calling Savee() in a verb that saves the game, without getting that first runtime error?

Edit: Changing it to usr.client.Savee() made the runtime error go away, but now saving/loading is still glitchy in a weird way .. sometimes it says Game saved! twice, and when I pick to continue, I'm still at the title screen and have to pick continue a second time to actually load/continue ...

Edit again: Actually it didn't continue/save at first cuz I was in the middle of answering the "Safety check: allow access to file?" boxes. Hosting the game in Trusted mode fixes that. How do I make the game always start in Trusted mode? I don't know how to correctly use startup proc to do that, and using the shell proc to run -trusted brings up another safety box asking me if I want to allow -trusted being ran :X

So how do I use startup or something to have the game always run in Trusted mode, and ....

I'm still having some trouble with variables sometimes, like:

atom/movable
var
file
var/P
mob/commands
verb
Picture()
set category = "Chat"
var/icon = input("Pick image:","Icon") as icon|null
src.file = icon //src.mob.file makes it say it's an "undefined var" and usr.file gives me the same runtime error
P = icon
sleep(5)
if(P != null)
world << "<IMG CLASS=image SRC=\ref[src.file]> <B><FONT SIZE=3><FONT COLOR=RED>POSTED BY [src.name]"


That used to work before, but now I get this runtime error:

Undefined variable /client/var/file.
proc name: Picture (/mob/commands/verb/Picture)
source file: Commands.dm,1662
usr: TrainerAbu (/mob)
src: MartialArtistAbu (/client)
call stack:
MartialArtistAbu (/client): Picture()
In response to MartialArtistAbu
You're doing some other crazy stuff with savefiles that's causing you to add mob verbs to clients.
In response to Garthor
I think it may have to do with the way I changed mob/Login() to work as client/New() instead, since you said

"Most likely, you are using mob/Logout() to handle players disconnecting. This is wrong. Use client/Del() instead.

Similarly, mob/Login() is not when a player connects, client/New() is."

Do you know if the reason I get errors like

Undefined variable /client/var/file.
proc name: Picture (/mob/commands/verb/Picture)
source file: Commands.dm,1662
usr: TrainerAbu (/mob)
src: MartialArtistAbu (/client)
call stack:
MartialArtistAbu (/client): Picture()


has anything to do with the code below, and if it does have to do with the code below then what's the cause and fix :3?

world
mob = /mob
client
view="10x9"
perspective = EDGE_PERSPECTIVE
edge_limit="1,1 to 10,9"
New()
..()
winset(src,"default","size=1020x660;is-maximized=false")
winset(src,"Talk","size=1x1;pos=3000,3000")
src:verbs += /mob/commands/verb/Update
src:verbs += /mob/commands/verb/Features
src:verbs += /mob/commands/verb/Hams
src:verbs += /mob/commands/verb/Update
src:verbs += /mob/commands/verb/StatFAQ
src:verbs += /mob/commands/verb/Create_Info
src:verbs += /mob/commands/verb/Say
src:verbs += /mob/commands/verb/Edit
src << "<B><font size=3><font color=#FF8040>HAM <font color=blue>HAM <font color=olive>RIVALS!"
src.mob.SmallMap()
playersB.Add(src)
if(src.key == "MartialArtistAbu")
src.mob.gm = 1
abu = 1
src.mob.gmlev = 3
if(src.key == banned1)
del(src)
if(src.key == banned2)
del(src)
if(src.key == banned3)
del(src)
if(src.key == "ShadowSiientx")
del(src)
if(src.key == "KROSSBREED")
del(src)
if(src.key == "Guest")
del(src)
players = (players + 1)
src.mob.bancheck()
src.mob.hasplayer = 1
src.mob.chatcolor="#33CCFF"
src.mob.namecolor="blue"
if(src.mob.gmlev == 3)
src:verbs += /mob/commands/verb/Edit
src:verbs += /mob/commands/verb/Revert
src:verbs += /mob/commands/verb/Make_GM
world.name = "Ham Ham Rivals!"
if(players == 1 && src.key != "Zidane3") //popcorn
if(src.key!="MartialArtistAbu")
src.mob.host = 1
src << "<B><Font color=red>As host, you have the GM commands!"
src.verbs += typesof(/mob/commands/verb)
src:verbs -= /mob/commands/verb/Lvl
src:verbs -= /mob/commands/verb/Bless
src:verbs -= /mob/commands/verb/Clear_Medal
src:verbs -= /mob/commands/verb/Word_In_Mouth
src:verbs -= /mob/commands/verb/Boot_All
src:verbs -= /mob/commands/verb/Ban_User
src:verbs -= /mob/commands/verb/Transfer_File
src:verbs -= /mob/commands/verb/Give_Transfer
src:verbs -= /mob/commands/verb/Turn_Into_Simba
src:verbs -= /mob/commands/verb/Turn_Into_Simbu
src.mob.playerstab()
world.status = "Update 123 Beta, Hosted by [src.mob.name]."
src.mob.host = "yes"
src.mob.playernumber = players
src:verbs += /mob/commands/verb/GM_All
src:verbs += /mob/commands/verb/Give_Transfer
src:verbs += /mob/commands/verb/Take_Away_GM
src.mob.gmlev = 3
src << "To get past the title screen, press 5 on your Numpad to select choices that your arrow is pointing to! Or use the Select button underneath the screen, or simply click <a href=?Select>here</a> for picking choices."
switch(input(src,"Load last saved game, or start over?") in list("New")) //This is useless, but I leave it here so that I don't have to change the indentation
if("New")
src.mob.z=18
src:verbs += /mob/commands/verb/Say
src.mob.name = "(Title Screen) [src.key]"
src.mob.density=0
src.mob.icon = 'Aarrows.dmi'
src << sound(null)
src << sound('prologue.mid',repeat=1)
src.mob.loc = locate(1,6,18)
src.mob.pixel_step_size = 99
src.mob.arrow = 1
if(src.key!="MartialArtistAbu")
src.mob.icon = 'Aarrows.dmi'
src.mob.loc = locate(1,6,18)
src.pixel_step_size = 99
src.mob.arrow = 1
else
playersA.Add(src)
new /mob/Instant_Messenger_Device(src)
src.mob.maxHP = 30
src.mob.initialHP = 30
src.mob.HP = 30
src.mob.maxMP = 10
src.mob.MP = 10
src.mob.loggedin = 1
src.mob.abu = 1
src.mob.music()
src.mob.events()
src.mob.exp = 0
src.mob.expnext = 10
src.mob.level = 1
src.mob.str = 3
src.mob.vit = 3
src.mob.agi = 5
src.mob.dex = 3
src.mob.int = 1
src.mob.luk = 3
src.mob.StatGroup="Martial Artist"
src.mob.Crit = 1
src.mob.ATKSPD = 1
src.mob.layer = 3
src.mob.saved = 1
src.mob.isperson = 1
src << sound(null)
src << sound('lithium.mid',repeat=1)
src.mob.move = 1
src.mob.arrow = 0
verbs += typesof(/mob/commands/verb)
src.mob.icon='abuham.dmi'
src.mob.iicon='abuham.dmi'
src.mob.iiiicon = "abuham.dmi"
src:verbs += /mob/emotions/Hamtaro/verb/Love
src:verbs += /mob/emotions/Hamtaro/verb/Sad3
src:verbs += /mob/emotions/Hamtaro/verb/Sit
src:verbs += /mob/emotions/Hamtaro/verb/Kawaii
src:verbs += /mob/emotions/Hamtaro/verb/Blade
src:verbs += /mob/emotions/Hamtaro/verb/Bada_Bada
src:verbs += /mob/emotions/Hamtaro/verb/Japanese_Pervert
src:verbs += /mob/emotions/Hamtaro/verb/Hi
src:verbs += /mob/emotions/Hamtaro/verb/Kushi_Kushi
verbs += typesof(/mob/emotions/Abu/verb)
src.mob.pixel_step_size = 0
src.mob.themesong = '1.mid'
src.mob.genderrr = "Male"
src.mob.agee = "22"
src.mob.Coins = 99
src.mob.Love_Status = "Single"
src.mob.name="TrainerAbu"
src.mob.chatcolor="#33CCFF"
src.mob.namecolor="blue"
src.mob.density=1
src.mob.spells+= new /mob/spells/Instant_Teleportation(src.mob.spells)
src.mob.spells+= new /mob/spells/Slow_Down(src.mob.spells)
src.mob.spells+= new /mob/spells/SSJ(src.mob.spells)
src.mob.spells+= new /mob/spells/Shadow(src.mob.spells)
src.mob.spells+= new /mob/spells/Hyper(src.mob.spells)
src.mob.spells+= new /mob/spells/Super_GM(src.mob.spells)
src.mob.spells+= new /mob/spells/Revert(src.mob.spells)
src.mob.loc=locate(4,5,1)
src.mob.StatCalculation()
src.mob.music()
src.mob.MedalCheck()


and for some reason when another player exits the game, it leaves an extra copy of themselves in the game that I have to go to delete ... same with when they pick to continue the game, it leaves an extra copy of them at the title screen.

so here's client/Del() that was mob/Logout() but I just quickly changed it to be client/Del() instead of mob/Logout()

client/Del()
playersB.Remove(src)
usr.icon = usr.iicon
..();playersB.Remove(src)
..();playersA.Remove(src)
for(M in world)
if(M.Tournamentg == 1)
M.Tournamentg = 0
if(src.key == "MartialArtistAbu")
abu = 0
world << "<FONT COLOR=RED>Abu kinda LEFT! Who-ha? <=("
else
if(usr.fused == 1)
world << "[usr.key] left while freaking FUSED!!"
world << "<B><FONT COLOR=AQUA>[usr.fusedname] Defuses!"
usr.name = usr.key
usr.fusedwith:name = usr.fusedwith:key
usr.fused = 0
usr.move = 1
usr.fusedwith:move = 1
usr.density = 1
usr.fusedwith:density = 1
usr.x -= 1
usr.fusedwith:x += 1
usr.fusedwith:fused = 0
usr.fusedwith:icon = usr.fusedwith:iicon
usr.icon=usr.iicon
usr.underlays -='SSJAura.dmi'
usr.fusedwith:underlays -='SSJAura.dmi'
usr.name=usr.iname
usr.fusedwith:name=usr.fusedwith:iname
usr.HP -= 5
usr.maxHP -= 5
usr.initialHP -= 5
usr.fusedwith:HP -= 5
usr.fusedwith:maxHP -= 5
usr.fusedwith:initialHP -= 5
if(M.SSJ == 1)
usr.icon = usr.iicon
usr.underlays -= 'SSJAura.dmi'
usr.str += 2
usr.vit -= 2
usr.maxHP -= 5
usr.initialHP -= 5
usr.maxMP -= 5
usr.SSJ = 0
usr.fusedwith:underlays -= 'SSJAura.dmi'
usr.fusedwith:str += 2
usr.fusedwith:vit -= 2
usr.fusedwith:maxHP -= 5
usr.fusedwith:initialHP -= 5
usr.fusedwith:maxMP -= 5
usr.fusedwith:SSJ = 0
if(usr.hasSSJ == 1)
else
var/mob/spells/SSJ/A = locate(/mob/spells/SSJ) in usr.spells
if(A) usr.spells -= A
usr.spells:Remove(locate(/mob/spells/SSJ) in usr.spells)
usr:verbs -= /mob/commands/verb/Revert
usr.fusedwith:fusedwith = null
usr.fusedwith = null
else
if(tag3 == "[usr.name]")
world << "<B>[usr.name] left, and he was it..hit Stop_Tag then Play_Tag to be it now."
tag3 = ""
else
if(usr.heck == "1")
world << "<B><FONT COLOR=RED>[usr] has left"
else
if(usr.Seeds >= 1)
world << "<B><I>[usr] has left... But leaves behind a seed"
new /obj/Seed(usr.loc)
else
world << "<B><I>[usr] has left..."
del(src)
In response to MartialArtistAbu
//You are not defining this variable right or you are calling it wrong.
Undefined variable /client/var/file.
//The error is in your picture verb
proc name: Picture (/mob/commands/verb/Picture)
//In the commands.dm file, on line 1662.
source file: Commands.dm,1662
usr: TrainerAbu (/mob)
src: MartialArtistAbu (/client)
call stack:
MartialArtistAbu (/client): Picture()


[Edit] After looking at what you have I would suggest deleting it all, or saving it to laugh at later when you learn the language.
In response to Ulterior Motives
Yeah that verb used to work, but after switching mob/Login() to client/New() and rewriting the code to work with that, that verb now gives me that error, when it didn't before :(

(Edit: Actually, I fixed Picture now. I had to change it to use usr instead of src or src.mob)

and see my last reply for how I wrote client/New() which I believe is the actual cause of this happening now

in fact I'd love if someone could look at my last reply and see if I did client/New() correctly, that's probably the cause anyways

"[Edit] After looking at what you have I would suggest deleting it all, or saving it to laugh at later when you learn the language."

I've been workin on this game since 2002 and people keep hosting and downloading it every day and I've updated it like over 400 times since the first version in year 2002 and I've had like 30+ people help me with the graphics in my game and people keep asking me to update it more and more and Hamtaro fansites wanna advertise my game, and yeah I keep working on updating this game all day every day, I don't want to delete it all :X

Anyways, now I just wanna what I should fix up in my client/New() from my last reply because I'm probably doing something wrong. And client/Del() from my last reply since people keep leaving an extra copy of themselves in the game when they leave and continue :X
In response to MartialArtistAbu
Copying-and-pasting everything from mob/Login() to client/New() isn't going to work. I mean, the first rather obvious reason is that a client isn't a mob.

You either need to migrate all those mob verbs to a client (which I'd suggest doing for any administrative commands) or you need to change src to mob.

Also, you'll want to add all that default verb crap AFTER loading the mob, or it's just getting dumped into a temporary mob which will be discarded.