@Nathaniel_Roberts mentioned how he would like a timer mechanic in a mission that he is working on. I dug into it and here be the skinny.
Normally in Lua there is access to the command os.clock(), which returns the number of seconds the script has been running. As this is a derivative of Lua running in the Empty Epsilon game engine, things are a little different. Similar idea though.
Here is an example of how it works.
Inside of the [color=blue]init()[/color] function, we need to set up the basis for a clock by assigning a variable:
currentTime = 0
I am also going to define two variables for my timer:
timer1Total = 30
timer1Active = true
Only currentTime is required this early on. The timer settings can be defined later in the script, or there can be multiple timers, etc.
The game-loop function [color=blue]update(delta)[/color] has the parameter “delta”, which is defined by the deeper game engine. This delta is the time difference since the last pass of the game loop (30, maybe 60 times a second). This makes delta a very useful piece of information.
At the top of the game loop, you want to update the currentTime variable:
currentTime = currentTime + delta
Now you can use currentTime as a global game timer (in seconds since mission began).
I want an event to happen 30 seconds into the mission start. My timer logic looks like this:
if timer1Active and (currentTime > timer1Total) then
timer1Active = false
-- <<DO STUFF HERE>>
end
by using timer1Active and setting it to false on trigger, means that the events won’t trigger every loop past the 30 seconds mark (causing mayhem).
You can define a timer within [color=blue]update(delta)[/color], based on a previous event. This is probably the wiser approach since when the mission actually starts people aren’t fully logged in / set up / etc. These would be the types of commands you use here:
timer2Complete = currentTime + 30
timer2Active = true
then later on for the if-check:
if timer2Active and (currentTime > timer2Complete) then
timer2Active = false
-- <<DO MORE STUFF HERE>>
end
Hope this helps, enjoy!