ID:1497872
 
Code:
        SaveChar()

var/savefile/F = new("Saves/[src.ckey].sav")
if(!fexists(F)) // If the save DOES NOT exist
var/savefile/Save = new("Saves/[src.ckey].sav")
src.Write(Save) // line 22

fdel("Saves/[src.ckey].sav")


Problem description:
runtime error: Failed to write variable Health to savefile Saves/lugia319.sav. The value being written was /MaxStat (/MaxStat).
proc name: SaveChar (/mob/proc/SaveChar)
source file: SaveLoad.dm,22
usr: Lugia319 (/mob)
src: Lugia319 (/mob)
call stack:
Lugia319 (/mob): SaveChar()
Lugia319 (/mob): ManSave()


I have no idea why this error is occurring.
Are you overriding Write() anywhere? You should also be using Save["index"] << src instead of calling Write() directly. Are you using any libraries or anything of that nature that might be conflicting?
I didn't touch Write() and I'm only using my clearspaces lib. And the default action of Write() should make Save[index] unnecessary. For most things anyway.
It's bad practice to call Write() manually in most cases, it gives you less control over how things are saving. Show more details about the variable that's failing to write, if you remove that variable does it work properly or spawn a new error?
It moves down to the next defined variable. It even has issues with strings.
Then you'll have to show more about said variables, seems you're using some kind of stat management datums, there's obviously something about those that are failing to save. If you only save normal non-datum variables does it work?
MaxStat
var
Name = "" // Stat name
Value = 0 ; MValue = 0 ; // Current and max values
BaseValue = 0 ; // Value to return to (if necessary)

// Sets up the stat base values
New(var/name, var/value, var/base)
..()
src.Name = name
src.MValue = value
src.BaseValue = base ; src.Value = base

Del()
..()

proc
Stat2Text()
return "[src.Value]/[src.MValue]"


And no, like I said in my previous comment, strings fail to write as well. All variable types fail to write. num, text, and datum.

EDIT: Variable definition.

        MaxStat // Stats that go from 0% to 100%
Health = new("Hp", 100, 100) // Damage you can take before "dying"
I didn't notice before, but you're using fexists() wrong, it takes a string as an argument not a file reference, you should be calling it before you ever create a savefile variable. You also don't need to fdel() the save for this, it'll automatically overwrite what it needs to, which is why you want to use the index-based << method, so it knows how to handle new data properly.

This demo I wrote up using your code works just fine.
MaxStat
var
Name = "" // Stat name
Value = 0 ; MValue = 0 ; // Current and max values
BaseValue = 0 ; // Value to return to (if necessary)

// Sets up the stat base values
New(var/name, var/value, var/base)
..()
src.Name = name
src.MValue = value
src.BaseValue = base ; src.Value = base

Del()
..()

proc
Stat2Text()
return "[src.Value]/[src.MValue]"


mob
var
MaxStat
Health = new("Health",100,100)
Magic = new("Magic",10,10)
string = "Hello world!"
verb
SaveMe()
client.SaveChar()

LoadMe()
client.LoadChar()

SetHealth(n as num)
Health.Value = n

SetMagic(n as num)
Magic.Value = n

Stat()
..()
if(statpanel("Debug"))
if(Health) stat("Health: ",Health.Stat2Text())
if(Magic) stat("Magic: ",Magic.Stat2Text())

client
proc
SaveChar()
var/savefile/Save = new("Saves/[src.ckey].sav")
Save["player"] << src.mob
Save["player/X"] << src.mob.x
Save["player/Y"] << src.mob.y
Save["player/Z"] << src.mob.z

LoadChar()
if(fexists("Saves/[src.ckey].sav"))
var/savefile/Save = new("Saves/[src.ckey].sav")
var/mob/loaded_mob
Save["player"] >> loaded_mob
if(loaded_mob)
var
loaded_x = Save["player/X"]
loaded_y = Save["player/Y"]
loaded_z = Save["player/Z"]
loaded_mob.loc = locate(loaded_x,loaded_y,loaded_z)
var/mob/old_mob = src.mob
mob = loaded_mob
old_mob.loc = null
I don't know if I was supposed to run that in an isolated environment or not, but I did. And it got a "bad output" error. Did you test this yourself?

EDIT: In fact, similar to my issue, it'll only give an error the first time, and then work properly every time afterwards.
I tested it myself in a clean environment, yeah. Worked each time without any runtime errors or issues.

I'm wondering though, are you running the beta using threading?
I am. Tried it with threads on and off, throws the same "bad output" error.
Let me update to that real quick and see what happens.
Nope, still working perfect for me using the latest beta.
Reverted to the current stable release and both my personal fix after fixing fexists() and your demo you've shown work fine. Not sure if it was my machine or what. But all's well that ends well I suppose.