ID:2365505
 
Problem description:
So I've been playing around with the list2params function for some save functionality, so far so good I thought, but it didn't quite work as intended..

So far, I've tried to take an objects vars list, and using list2params to make it into text form that should be easier to save. However, upon doing so, list2params shows me all the variable names in text form... Without the values themselves..

Am I missing something here?

If needed I can throw out my code as well, but its really as simple as list2params(obj.vars)


Thanks in advance!

vars is a special list. I'm not the one to say how or why.

If you want a standard associative list of variable names associated to their values, you can do this:
// Make a new list, copying everything in vars.
var list/var_values = vars.Copy()

// Make all the associations.
for(var/v in var_values) var_values[v] = vars[v]

// Now list2params() should include the associations.
src << list2params(var_values)

That said, I don't see how this would be easier to save, and it definitely wouldn't be easier to load. You lose information like whether a number is actually a number or a string, information on sub-objects, whether a variable actually should be saved or not. A better option would be json_encode(var_values), but the bigger question is why you're avoiding the built-in functionality of savefiles and Read/Write.
Thanks a lot, I had no idea the variables list was a special snowflake, good to know I wasn't being completely stupid.

I have thought about using save files, and frankly I think they may suit my purpose better, the thing with .txt files over .sav files is that if anything goes wrong, I can just pop in, change a variable/remove an entry and load it back in. Save files are a tad trickier for that regard..

But I'll probably go with save files over these then.
In response to Laser50
With the savefile procs ExportText and ImportText, you can open up savefiles as human readable text files to read and make changes to them.
You can even store the text version of it instead of the savefile version if you want it to be easy to edit, then just ImportText() on loading.
Another thought, if you want to preserve the difference between strings and numbers at least, is to use JSON encoding instead of list2params.