Having data update when app is closed (idle)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
TheHistoricApple
Prole
Posts: 26
Joined: Sun Jan 15, 2017 6:46 am

Having data update when app is closed (idle)

Post 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?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Having data update when app is closed (idle)

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
TheHistoricApple
Prole
Posts: 26
Joined: Sun Jan 15, 2017 6:46 am

Re: Having data update when app is closed (idle)

Post 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
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Having data update when app is closed (idle)

Post 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
Last edited by Nixola on Wed Jun 07, 2017 7:04 pm, edited 1 time in total.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
TheHistoricApple
Prole
Posts: 26
Joined: Sun Jan 15, 2017 6:46 am

Re: Having data update when app is closed (idle)

Post by TheHistoricApple »

What does the

Code: Select all

f:read("*a)
Do i get an error saying number expected got string
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Having data update when app is closed (idle)

Post by Nixola »

That should just be f:read(). I got confused with Lua files, that's a LÖVE file.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests