Yeah I saw that and I just had to move it to the event listener for it to update. So know I just have to save it, which hopefully that will work for me. Thanks for the help! Also should I put that code it a text file (txt) or a lua file, and should I have any code in the main file that would accommodate the saving and loading?
Also where does GGdata come from am I making a file with that name or do I have to download something? thanks for all your help!
If you decide to save your data for use between game launches, you should read the documentation associated with GGdata. It is quite thorough and easy to implement.
Ok so I’ve been at this for a couple days and I still can’t seem to figure it out. what I’m using https://github.com/robmiracle/Simple-Table-Load-Save-Functions-for-Corona-SDK I have my table all set up and it updates if the score > highscore but it doesn’t save when the game end. I’m using
loadsave.saveTable(ht.number, “myTable.json”, system.DocumentsDirectory)
but it doesn’t seem to work I’ve also put his loadsave lua file in my games file and required it in the scene but it still doesn’t work, anyone know what I can do to save it? thanks for anyone’s help!
Is ht.number a table?
You really will need to provide more of your code if you expect someone to be able to figure out what you might be doing wrong.
Sorry for how vague I was here is some of my code
my table
local ht = {}
ht.number = 0
my event listener for when I add the score when I push on the object
local function addToScore()
_G.score = _G.score + 1
scorenumber.text = _G.score
if (_G.score > ht.number) then
ht.number = _G.score
highscorenumber.text = ht.number
loadsave.saveTable(ht.number, “myTable.json”, system.DocumentsDirectory)
end
transition.moveTo(cookie, {x= math.random(30, 280), y= math.random(-20, 500), time=0})
end
I hope that’s enough let me know if you need to see anything else to help.
Well, I haven’t used Rob’s code before, but from what I can tell at a quick look, it’s intended to save a table. ht.number is not a table. ht is the table. Have you tried saving and loading that?
Yea I did that as well, one of the things I realized I’m not doing is I have no load code do you know where I should put it at in the composer layout?
Ok so I’ve gone back to what you told me to use since you know how to use it so I required it
local GGData = require (“GGData”)
I set the value of it
local highscore = GGData:new()
highscore.anotherValue = 0
I update it and save alongside the score
local function addToScore()
_G.score = _G.score + 1
scorenumber.text = _G.score
transition.moveTo(cookie, {x= math.random(30, 280), y= math.random(-20, 500), time=0})
if (_G.score > highscore.anotherValue) then
highscore.anotherValue = _G.score
highscorenumber.text = highscore.anotherValue
highscore:save()
end
end
but I get an error with this in the GGData file
path = system.pathForFile( self.path … “/” … self.id … “.box”, system.DocumentsDirectory )
local file = io.open( path, “w” )
It says attempt to concatenate field ‘id’ (a nil value)
I also changed the box to highscore but it doesn’t work, since you know how it works do you know what I’m doing wrong?
Anyone know what I’m doing wrong?
Ok so I changed everything from highscore to box and it now looks like this for me setting it up.
local box = GGData:new(“sample”)
box:set(“message”, “hello world”)
box.anotherValue = 0
so now I don’t get the error but it still doesn’t save, anyone know what im doing wrong, will you tell me how you save your highscores using ggdata?
Could anyone help me with this? It’s the only thing stopping me from finishing my game.
Are you actually saving the data?
box:save()