ID:147671
 
BYOND(336.856) Error: circular serial object pointer in: players/cadence

I get this error when I load a mob from a savefile. I edited the /mob/Read() proc so it may have something to do with it.

mob/Read(savefile/F)
F["mob"]>>src
var/x
var/y
var/z
F["old_x"]>>x
F["old_y"]>>y
F["old_z"]>>z
F["icon"]>>src.icon
src.loc=locate(x,y,z)
..()


I would have posted this in Code Problems but everything works fine. I just get that error. Maybe everything's not working as fine as I think it is.

Cadence
First of all, the default action of mob/Read() already loads all the variables into the mob, and various other things.

Second, you are declaring var/x, var/y, and var/z, but those are already declared as mob variables.

Your problem is either the var/x, var/y, and var/z, or that you are using F["mob"]>>src, which really doesn't work that way. I'd suggest getting rid of that, changing x/y/z to X/Y/Z, and moving ..() to the start of the proc.

Oh, and this should be in Code Problems, because it's not a BYOND bug.
In response to Garthor
Garthor wrote:
Your problem is either the var/x, var/y, and var/z, or that you are using F["mob"]>>src, which really doesn't work that way.

Right, I believe it's the F["mob"] >> src line. The Read() proc is called when a datum is read from a savefile, so by definition it gets called again when you do F["mob"] >> src. BYOND is detecting that the mob is already in the process of being read when you hit that line a second time, so it aborts (otherwise it would quickly crash as Read() kept calling itself).

Generally, overriding Read() is only necessary if you need to do something funky with the savefile directories/variables that isn't handled by the default action. The vast majority of people probably don't need to override Read(), and certainly in your (Cadence) case, it doesn't appear to be necessary. Instead, make it a different proc name (like ReadMob() or whatever you want) and call that when you want to load the mob. mob/Read() then gets called automatically and does its default, which is what you probably want.
In response to Garthor
Second, you are declaring var/x, var/y, and var/z, but those are already declared as mob variables.

That wouldn't make a difference. Anyone can make variables inside object procs that have similar names to variables that actually belong to the mob.

For example, I could have something like this:
mob/proc/RestoreCharacter()
var/savefile/F = new ("data/[ckey].sav")
var/name = ""
F["name"] >> name
if(!name) src.name = RandomNameGenerate()
else src.name = name

The problem with the code he posted is the recursive savefile reading, of course.
In response to Air Mapster
Thanks, that did the trick.

Cadence
In response to Spuzzum
Well, I thought you were able to do that, but I wasn't quite sure. Oh well, it's bad practice to do it anyway.