Hi guys, i'm having some issues regarding reading and writing data in a external file.
I wanna be able to save multiple highscores in a file and read them when it is needed, is that possible? Like, assume I have four minigames, when I play minigame #1 I want to save and read its score on line #1 of the save.txt file and so on.
This is what I have so far:
function GCendingScreen:loadHighscore()
local file = io.open("|D|data.txt", "r");
local score = 0;
if file then
score = tonumber(file:read());
io.close(file);
end
return score;
end
function GCendingScreen:saveHighscore(savedScore)
local file = io.open("|D|data.txt", "w+");
if file then
file:write(savedScore);
io.close(file);
end
end |
The problem here is that I save and read only one highscore. Not only that but the saveHighscore function overwrite my previous data.txt file... Is there a way to specify it?
Comments
http://appcodingeasy.com/Gideros-Mobile/Save-and-load-data-module-for-Gideros-Mobile
To not overwrite information you need to open file with append option as
http://www.lua.org/pil/21.1.html
Likes: thanhquan1512
thank you for your contribution
Likes: ar2rsawseen
Ultimate Games on Appstore
Ultimate Games on Google Play