ID:266312
 
I just learned how to save a simple text string using a save file! I am so very pleased with myself :oD

Now, however, I have run into a roadblock:

client/proc/SaveStats()
var/savefile/S = new("PlayerSaves.sav")
var/path = "[ckey(src.key)]/[ckey(src.name)]/stats"
S["[path]/stat1"] = list()
S["[path]/stat1"]["name"] = "Gold"
S["[path]/stat1"]["value"] = "[usr.gold]"

For some reason, this does not work at all. How do I work a list into this savefile code?
For some reason, this does not work at all. How do I work a list into this savefile code?

I've just starting using savefiles myself, but I think you may need to use the << and >> operators rather than equals signs. There should be info about them in the Reference.
Guy's right about using the << operator. As for whether to use << or >>, just think of it as the arrows point in the direction of data flow. For example:
S["path"] << data

puts data into the savefile at "path." Whereas
S["path"] >> newdata

puts the stuff stored at "path" in the savefile into the var newdata.

Also, with your list, I'd create the list first, then save it to the file:
client/proc/SaveStats()
var/savefile/S = new("PlayerSaves.sav")
var/path = "[ckey(src.key)]/[ckey(src.name)]/stats"
var/mylist[0]
mylist["name"] = "Gold"
mylist["value"] = "[usr.gold]" // I'd shy away from using usr here
S["[path]/stat1"] << mylist

Although, using a list to begin with is really creating more work for yourself. What I'd really do is save "name" and "value" as subdirectories of "stat1."
client/proc/SaveStats()
var/savefile/S = new("PlayerSaves.sav")
var/path = "[ckey(src.key)]/[ckey(src.name)]/stats"
S["[path]/stat1/name"] << "Gold"
S["[path]/stat1/value"] << "[usr.gold]" // I'd shy away from using usr here
In response to Air Mapster
Thanks, Air Mapster! I knew about the << and >> operators, but I'm still a bit flustered by the whole concept. And just so that you know, I didn't actually use usr... that was just a test example. Thanks for your time in helping!

-Lord of Water