ID:1074770
 
(See the best response by FIREking.)
This was my code to save/load things last night and it was working perfectly. I noticed that it stopped working after I added these lines.

world // World stuff
view = 6

New() // When World is created
LoadNames() // Load Names/Villages
LoadVillages()
..()

Del() // When World is closed
SaveNames() // Save Names/Villages
SaveVillages()
..()

var

list
Names = list()
Villages = list()


Here are the saving procs
    SaveNames() // Saves names to SaveFile
var/savefile/F = new("Names")
F["Names"] << Names

LoadNames() // Loads names from SaveFile
var/savefile/F = new("Names")
F["Names"] >> Names

SaveVillages() // Saves Villages
for(var/Village/X in Villages)
X.Save()

LoadVillages() // Loads Villages
for(var/Village/X in Villages)
X.Load()
// These next are under Village datum //
Save() // Saves village data
var/savefile/F = new("Villages/[src.Name]")
src.Write(F)

Load() // Loads village data
var/savefile/F = new("Villages/[src.Name]")
src.Read(F)


I'm a big fan of Read()/Write() and last night they WERE working, I tested them with debugging verbs that called Save/Load procs listed under world.New()

Each time I run the game, and use a villages() verb (Which returns the names of all Villages in list/Villages) it only returns the one that I created myself in. And I can name myself the same thing over and over again because the LoadNames() doesn't seem to work properly. Any ideas?

The creation of save files without me personally calling the Save() functions tells me that world.Del() is working properly (or at least, is doing something). That leaves world.New() to not be working properly and I can't imagine why.

EDIT: Upon closer investigation, I realize that list/Villages() is initialized to an empty list upon creation, so there's an excuse for that to not work. The names, however, does not.
I'm not entirely sure about this, but I think you might have a problem here:

    
LoadVillages() // Loads Villages
for(var/Village/X in Villages)
X.Load()


Isn't Villages an empty list? Or is there some other part of the code that populates this list? If so, you should do that before calling LoadVillages()

And a side-note, world.New() doesn't do anything so calling the parent is not necessary
Though shall not call Read/Write procs directly. Use the >> and << operators.
In response to Jemai1
Jemai1 wrote:
Though shall not call Read/Write procs directly. Use the >> and << operators.

That's fine and dandy, but as you'll see for the saving names section I never actually call Read/Write directly.
Best response
If villages list is empty, it will never load anything. If you don't load names first, it won't know what to load.

Even if you loaded names list first, you'd still have an empty villages list to loop through.

You'll probably want a way to save and load a village by name. Then you'd load the name list, and then loop through each name to LoadVillageByName()
In response to Lugia319
Uh-huh. If you omit the procs with Read and Write (LoadVillages/SaveVillages), does the problem still exists? Also, is your folder name the same with the .dmb file?
Yes and Yes.
I agree with Fireking here, if the lists empty when the world starts your just loading nothing and wasting time, make sure they are in before you run the load and save procs.

I know about the village list problem. I even edited my original post BEFORE Fireking posted saying, "Oh yeah, I noticed that". I'll address it later. At the very least, I should be able to fix the names thing because the names list is populated by the load function. The whole point of using the savefile method was so I wouldn't have to bother with text2file and file2text when dealing with names.
You do not have a check if the savefile exists.

So, what happens is that:
when there is no Names savefile, your code will create one. ( var/savefile/F = new("Names") )
then, you will read it. ( F["Names"] >> Names )

What you have read is most likely null. Then, when you close the game, you are saving a null variable. Or if you have Names += name1, your Names var will equal to name1. When you add another, you'll get name1name2. The condition in if(name1 in name1name2) will not be satisfied.

tl;dr Your savefile is most likely corrupted. Delete it then properly handle loading when there is no savefile.
LoadNames()
if(fexists("Names"))
var/savefile/F = new("Names")
F["Names"] >> Names
From what I can see of your code, your Villages list is never ever populated. That was my main point.
Looks like you were right jemai. Apparently I do have to check to make sure that a save file exists before making one. Thanks.