ID:1557368
 
(See the best response by Stephen001.)
Code:
runtime error: Failed to write variable Name to savefile players/Alaricus.sav.  The value being written was "Testington".
proc name: Write (/mob/Write)
usr: Alaricus (/mob)
src: Alaricus (/mob)
call stack:
Alaricus (/mob): Write(players/Alaricus.sav (/savefile))
Alaricus (/mob): SaveC()
Alaricus (/mob): Save()


Problem description: I... I don't even know. Last time I used the save verb, it worked just fine. I have no idea what broke it, as I haven't used it in forever.

Here's the actual code:
mob/verb
Save()
usr.SaveC()
usr<<output("Save successful.","system")

mob
proc
SaveC()
if(src.cansave)
var/savefile/F=new("players/[src.key].sav")
Write(F)

mob
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
F["Level"] << src.Level
F.dir.Remove("cooldowns")


As you can see, the actual writing is very minimal, because in previous experience the other variables were being saved. I only specified those five, the first three for loading location purposes, the last one for resetting cooldowns, and the fourth one... I don't truly remember lol.

(Edit: Also, those three pieces of code are in reverse to how they're ordered in my source. I was just being lazy.)
The runtime speaks of a variable called Name, yet I'm not seeing it here.
That's what confuses me too. The variable exists, and is called multiple times.

My Save verb takes advantage of BYOND's default Write() proc, which writes all the variables that are attached to the mob (afaik). I have done a lot of coding since I added this in, but the last time I used it it worked fine. Now it isn't working at all and I have no idea why. I haven't even touched the code for save handling in months.

I even added the save command for the Name variable manually to the proc, and it still gives the same runtime error.
You shouldn't be calling Write() directly like that. BYOND gets confused about the context it's saving in, attempts to save client variables, duplicates objects instead of referencing them etc etc.

mob
proc
SaveC()
if(src.cansave)
var/savefile/F=new("players/[src.key].sav")
F << src


Let BYOND do it's pre-requisite pruning and translation via << first. This will call your Write() proc in turn, after that.
I'm getting a bad output error now. The only thing I changed was the last line, as you showed.

Is there anything else I would need to alter?
Can you post the full error on that?

By defining cooldowns under a tmp variable, you wouldn't have to remove them at the end of the save, and level is probably already saved right? - I don't think that is the source of the error though.
runtime error: bad output
proc name: SaveC (/mob/proc/SaveC)
usr: Alaricus (/mob)
src: Alaricus (/mob)
call stack:
Alaricus (/mob): SaveC()
Alaricus (/mob): Save()
Is there an existing savefile there, that you're now overwriting?
And just for the hell of it, these are my cooldown procs:
        cooldown(cooldown_name,cooldown_duration)
if(!cooldowns)
cooldowns=list()
if(cooldowns[cooldown_name])
cooldowns[cooldown_name]=max(cooldowns[cooldown_name],world.time+cooldown_duration*world.tick_lag)
else
cooldowns[cooldown_name]=world.time+cooldown_duration*world.tick_lag

on_cooldown()
if(!cooldowns)
cooldowns=list()
for(var/a in args)
if(a in cooldowns)
if(cooldowns[a]>world.time)
return 1
return 0

floor(var/v)
return round(v)
ceil(var/v)
. = round(v)
if(v-.>0)
return .++
In response to Stephen001
Stephen001 wrote:
Is there an existing savefile there, that you're now overwriting?

There was at first. I deleted it, and it's still giving the same error.

When it first happened it was on a different key too.
mob
Write(var/savefile/F)
..(F)
F["x"] << x
F["y"] << y
F["z"] << z
F["Level"] << src.Level


And make cooldowns a tmp variable.
I also should ask, why are you explicitly saving Level? Surely it's a saveable variable by default?
I'm not 100% sure how to go about making the cooldowns a temp variable, unless you're suggesting completely reworking how cooldowns work (which is a headache best left for a different time, I think).

Regardless, with both edits you posted added in, it's still giving the same error. Bad output.
To be honest I don't really remember. As I said, the last time I touched the coding for the save verb was MONTHS ago. It only (sometime within the past week) recently stopped working.

To test and be sure that cooldowns were not effecting anything, I uncommented the above procs and unchecked the 'Skills.dm' code file. Removed both cooldowns and level from the save proc, tried it again, still giving the same error. I even reverted it back to my original, with level and cooldowns removed, and it gave the original runtime error with name.
Show me where the Level and cooldowns variables are defined, please?
        Smash(mob/M as mob in get_step(src,src.dir))
set category="Hakuda"
if(ismob(M))
if(on_cooldown("Smash"))
src <<output("You cannot use this yet. ([floor((cooldowns["Smash"]-world.time)/world.fps)]s)","system")
return
if(src.cantattack)
return
var/cooldown = 200 - round(SmashRank/2)*50
var/multiplier = SmashRank*0.2 + 1
var/smashdist = round((SmashRank-1)/2) + 1
flick("punch",usr)
var/d = get_dir(src,M)
for(var/count=0;count<smashdist;count++)
step(M,d)
var/damage = M.Hit(usr,round((usr.CStr-M.CEnd/0.75)*multiplier),1)
range() <<output("[usr.Name] smashed [M] for [damage]!","system")
cooldown("Smash",cooldown)
usr.DeathCheck(M)
else
return

That is an example of cooldown being used in one skill, which has temporarily been removed from the game. Cooldown procs have been commented out as well.

mob
var
Level=1
CHP=100
MHP=100
CReir=100
MReir=100
BReir=100

The list is longer, but yeah. That's the specific section.
It's not the cooldown procs I'm interested in, it's the variable definition I want to see.

Level is saved by default, we don't need to repeat that in Write().
Cooldown is defined specifically in each skill, because they don't have a universal variable. Hence why the procs are necessary.
                if(src.cantattack)
return
var/cooldown = 200 - round(SmashRank/2)*50
var/multiplier = SmashRank*0.2 + 1

That's the specific coding that defines the proc variable in the above code. It's slightly different (mostly just numbers) for each skill.
But ... why are you doing F.dir.Remove("cooldowns") if there's not even a variable on mob named that?

Also, can you show me all of the variables you've defined on mob. I don't especially care if that is big.
If I remember correctly (and it has been a while), the cooldowns would not go away properly upon logout if I didn't do that. This was mostly because I was testing the game by constantly crashing then bringing up the server (via 'run' in DM).

It was nearly six months ago that I wrote these save procs, and they have been working fine up until today. I was on coding hiatus for a few months, but just recently picked it back up. I'd say... there's 2-3 weeks of new content that could possibly have broken something, but NOTHING I have added should be effecting the save system, as I have not altered anything that has anything to do with it.
Page: 1 2