This might not be the best forum to post this in, but I think my problem is more associated with game development than Lua Language…
My problem is the “common” need to develop a LOCAL high score framework, but with a slight twist perhaps. I want to update more than just scores in this case… perhaps the key point being update information in a text file, not just add/append new info into it.
Let’s imagine a practical and common example from Angry Birds. I want to keep a local record of which levels have been passed, which are locked/unlocked, what the high score is, etc… without using OpenFeint, GameCenter, or any external service. I want it all stored in the local text file located in the app’s “Documents” directory.
The problem I’m facing is how to update just one piece of data from the text file using the available File IO functions (file:write, file:read, etc.). I looked at some various score frameworks in the Code Exchange, including the one using JSON coding. It appears that the only way to update a text file is to read the entire file into a local variable, update elements of it, and then rewrite the entire text file again! Is this correct? It seems like an inefficient way of doing things, especially if my only intent is a quick 1-line update like changing “Level\_3-1 = incomplete” to “Level\_3-1 = complete”.
Ideally I’d like a method to locate just that piece of the text file (and the position of it) and then overwrite it with a new value. But I can’t figure out if this is possible or not. As I said, it appears from the current examples that the entire text file must be processed (file:read), updated, and rewritten (file:write).
Glancing at the “io:open” function, it appears there are other methods in addition to read and write (i.e. “a” is to append, “a+” is append/update, etc.). But I don’t see how to pinpoint or find the location of a particular string and then overwrite it at that precise position.
Any help or suggestions here? I see that other developers have clearly written local “score” frameworks, i.e. the one in Blast Monkeys which works similar to the one in Angry Birds. How was this done?
Thanks!
Brent [import]uid: 9747 topic_id: 5773 reply_id: 305773[/import]