Page 1 of 1
Having data update when app is closed (idle)
Posted: Wed Jun 07, 2017 4:02 pm
by TheHistoricApple
So i'm wanting to make a idle game. In which you upgrade buildings gain gold blah blah.
However i'm not sure how to go about updating the data while someone isn't online as i've never done any networking or any online development.
What would i need? Where should i start. Can i use a database instead of a dedicated server?
Re: Having data update when app is closed (idle)
Posted: Wed Jun 07, 2017 4:30 pm
by Nixola
Why do you need a server? You can just save the time when the app was closed, then when you open it you check how much time has passed and calculate all the things.
Re: Having data update when app is closed (idle)
Posted: Wed Jun 07, 2017 4:38 pm
by TheHistoricApple
i'm so stupid and your a genius.
So something like:
Code: Select all
function saveExitTime()
lasttime = os.time()
end
function comparetime()
os.difftime(os.time, lasttime)
end
function love.load()
comparetime()
end
Re: Having data update when app is closed (idle)
Posted: Wed Jun 07, 2017 5:47 pm
by Nixola
Just a simple subtraction could do:
Code: Select all
function love.quit()
local f = love.filesystem.newFile("lastTime", "w")
f:write(os.time())
f:close()
end
function love.load()
local f = love.filesystem.newFile("lastTime", "r")
if f then
local lastTime = f:read() -- was f:read("*a"), fixed now
diffTime = os.time() - lastTime
else
diffTime = 0
end
end
EDIT: how neat, phpBB automatically closes code tags if one forgets
Re: Having data update when app is closed (idle)
Posted: Wed Jun 07, 2017 6:14 pm
by TheHistoricApple
What does the
Do i get an error saying number expected got string
Re: Having data update when app is closed (idle)
Posted: Wed Jun 07, 2017 7:03 pm
by Nixola
That should just be f:read(). I got confused with Lua files, that's a LÖVE file.