The player has a “bank account”. They spend money on their store and receive money from customers.
They also receive money on a “daily” (of course it’s not realtime) basis from interest.
What’s the best way to automatically add to an integer every X seconds? What’s the best way to have an ongoing runtime for actions to take place that are not initiated by the user?
There are several ways you can go about this.
The “Best” way can really only be decided by you. However here is one example :
local gameTime = 0
local fullDay = 10000
local incrementTimer = true
local function updateGame(event)
--Update game time
if incrementTimer == true then
gameTime = gameTime + 1
end
--If the full day has been reached
if gameTime \>= fullDay then
incrementTimer = false
--do whatever, update account etc
--Reset day
gameTime = 0
end
end
Runtime:addEventListener("enterFrame", updateGame)
Actually, one question. When does incrementTimer get set to true again? It seems like after the first full day, the gameTime increment would stop. [import]uid: 85686 topic_id: 14209 reply_id: 52405[/import]