ID:150514
 
This always happens to me when I try to do something with savefiles (not counting using ron's library). I get an error on the asterisked line saying that it cannot modify null.name. At the same time, it does change the name of all mobs loaded to Poitney, which is exactly what this line should do. Clearly, "null"'s name is being modified. What's going on here?

for (var/g in flist("saved/"))
var/mob/m
f = new("saved/[g]")
f >> m
m.name = "Poitney"*
LexyBitch wrote:
This always happens to me when I try to do something with savefiles (not counting using ron's library). I get an error on the asterisked line saying that it cannot modify null.name. At the same time, it does change the name of all mobs loaded to Poitney, which is exactly what this line should do. Clearly, "null"'s name is being modified. What's going on here?

for (var/g in flist("saved/"))
var/mob/m
f = new("saved/[g]")
f >> m
m.name = "Poitney"*


Not sure, but the for loop ends before it sets m.name, and var/mob/m is local to that loop.

Alathon
In response to Alathon
Oops... that's an indentation error within the post, not the code. I've fixed it.
LexyBitch wrote:
This always happens to me when I try to do something with savefiles (not counting using ron's library). I get an error on the asterisked line saying that it cannot modify null.name. At the same time, it does change the name of all mobs loaded to Poitney, which is exactly what this line should do. Clearly, "null"'s name is being modified. What's going on here?

for (var/g in flist("saved/"))
var/mob/m
f = new("saved/[g]")
f >> m
m.name = "Poitney"*

I haven't gone over flist() or any of those functions yet at all (since I haven't needed them yet), but could it be that flist() is including . and/or .. in its list? If it is, then what you're seeing is that a failed load gives you the null mob m, which is what is giving you the error message, but subsequent loads are working correctly.
Try this to see which file is giving you the error:

for (var/g in flist("saved/"))
var/mob/m
world << "Loading saved/[g]"
f = new("saved/[g]")
f >> m
m.name = "Poitney"*
world << "Name changed to [m]"

Lummox JR
In response to Lummox JR
All saved mobs are being loaded correctly... all mobs are generating the same error. This is in itself incongruous... if all mobs are being loaded correctly (including having their names changed), then why is it generating an error saying the name cannot be changed?
LexyBitch wrote:
for (var/g in flist("saved/"))
var/mob/m
f = new("saved/[g]")
f >> m
m.name = "Poitney"*

You may have checked these but in case you haven't:

- Have you tried printing out the list of filenames you are getting this way?

- Have you tried doing an istype() on what you are getting from the savefile to see what it is?

I tend to avoid the order-based approach to storing data in savefiles because it's very error-prone and not extensible. If you decide to change the order of data later, it can be very difficult to deal with.
In response to LexyBitch
LexyBitch wrote:
All saved mobs are being loaded correctly... all mobs are generating the same error. This is in itself incongruous... if all mobs are being loaded correctly (including having their names changed), then why is it generating an error saying the name cannot be changed?

Strange problem. I think you'll have to narrow it down with some snippet tests. I would suggest putting in lots of debugging info similar to what LummoxJR suggested.

I tested it over here and it seemed to work without hitch:
mob/verb/testsave()
var/mob/M = new
M.name = "Original"
var/savefile/F = new("saved/[M]")
usr << "Saving [M]"
F << M

mob/verb/testload()
for (var/g in flist("saved/"))
var/mob/M
var/savefile/F = new("saved/[g]")
usr << "Loading [g]"
F >> M
usr << "Pre: [M]"
M.name = "Modified"
usr << "Post: [M]"

I tested with a single save, with multiple saves, in the same session, in different sessions, and so forth. It didn't have any problems. It really sounds like your routine is loading an invalid savefile and then attempting to modify null, but your above statements deny this. Hopefully you can get some more info.
LexyBitch wrote:
it does change the name of all mobs loaded to Poitney, which is exactly what this line should do.

heh, not even going to ask :)
In response to Flick
That was an example, a generic test case to disguise the delicate underworkings of the game the code is for. It does the same thing, for any variable changed to any value.