TheFalcon: How can I save a non-number value? For example, if I try to save a string:

add_loadsave("foo",0)
foo = "bar"

I get a nasty lua error and a broken savefile.

I've come across this before, although I was trying to save a table then, which was perhaps overly ambitious...

Do I need to convert my string to a series of numbers (uh oh...) and play around with register_savefile(int num) and save_number_key(char *key, s32b val) or is there an easier way?

(I could just output the string to a file, then read it from there, which would be *much* easier, but not ideal.)


NeilStevens: If you have to save a string, and no other option exists, you should be able to use a quark. Don't use quarks in situations where you'll be creating a lot of htem though.

KhymChanur: Have you tried add_loadsave("foo", "")? It works with 3.0.0

DarkGod: Yup it works in 3, but IIRC it does not in 2xx, I had to do some ugly things when I needed those, like .. convert the string to numbers :<

TheFalcon: I think I'll stick to quarks. It looks easier...

DarkGod: dunno about neil obsession with quarks, but I do not see how they will help you :)


TheFalcon: Perhaps I'm misunderstanding how quarks work, but...

If I use quark_add("foo") then the string foo will be added to the quark array, at the position given by a number returned. Then I can get back the string by doing quark_str(num) where num is the number returned earlier. So:

add_loadsave("num",0)
function foo()
    num = quark_add("foo")
end
function foo2()
    msg_print(quark_str(num))
end

should do what I want... (with appropriate hooks)

However, while quark_str() works, it only does so before I save and exit, not afterwards, so I don't know what's wrong. It seems quarks may not be the answer to the problem after all.

DarkGod: as I said, they are not :) Quark is just an array of strings, they are NOT saved. I do not even know why they exists.

NeilStevens: That's odd; I used a quark in the Minas Anor library quest, and it got saved.

KhymChanur: But if quarks aren't being saved, then how would object inscriptions be saved?

DarkGod: I would need to check your code, but from memory I recall it worked but only due to pure luck, not quarks ;=)

Module Developers Discussion/saving non-numbers (last edited 2006-04-03 10:12:53 by DarkGod)