Reputation: 9
I am completely new to the Lua programming language, I've only been working with it a few days in total. Although, I do have some experience in Python, C# and Ada.
I am currently trying to make a racing game, one of the aspects of the game I'm trying to include is a countdown timer that ends the game after 90 seconds, then returning to a high score screen, regardless of whether or not the player has eliminated all of their lives already. I haven't a clue what functions to include nor where the place the text in the main script. Some advice would be much appreciated.
Upvotes: 0
Views: 12456
Reputation: 1702
Use timer.performWithDelay to call a specified function after a delay.
Example
local function countdown( event )
print( "listener called" )
end
timer.performWithDelay( 1000, countdown, 90 )
Upvotes: 1
Reputation: 15508
When the game starts do:
local startTime = os.time()
local endTime = startTime+90
Then regularely do:
if os.time() >= endTime then
-- exit game
-- return to high score screen
end
until the game ends. Probably this would be in a callback function that gets called regularely. Depending on how your framework works, a loop might also work.
Upvotes: 1