# Timer Functions¶

## class timer¶

class timer

The low precision timer

timer timer()

Creates a timer that counts the time from the time of creation

Example: Creates a timer and stops it directly. Then the time will be displayed in the console.

local timer = timer()
print(tostring(timer:stop())) --Prints 0 Seconds, because we stop it directly

reset()

Resets the timer to 0

Example: Creates a timer and resets it directly. Just to demonstrate.

local timer = timer()
timer.reset(); -- Resets the timer to 0
print("Timer reset")

float stop()

Stops the time and returns it

Returns: (number) Time in seconds since the last reset or construction

Example: Creates a timer and stops it directly. Then the time will be displayed in the console.

local timer = timer()
print(tostring(timer:stop())) --Prints 0 Seconds, because we stop it directly

bool triggered(float time)

Allows to check if a certain amount of time has passed.

Parameters:

• float time: the time that should be passed
Returns: (boolean) if the time passed, returns true, otherwise false

Example: Creates a timer and asks if the time has passed since the timer was created.

local timer1 = timer()
if timer1:triggered(45) then
print("got the 45") -- This will never happen, because we call the function directly and so the time can not be 45 anytime
end
sleep(5000)
if timer1:triggered(5) then
print("Got the 0") -- This Functions will print 0, because the time 0 is passed directly
end

float stopAndReset()

Stops the timer, returns the time and resets it.

Returns: (number) Time in seconds since the last reset or construction

Example: This example creates a timer and stops it directly and resets it. Then it prints the time, that was got from timer

local timer1 = timer()
local time = timer1:stopAndReset()
print(time) -- prints 0, because we call this directly after we created it.

float getTime()

Returns the time in platform specific format. (i.e. Seconds since 1/1/1970)

Returns: time
char __tostring()

Returns the time that has elapsed since the timer was created.

Returns: a LUA string in this format %gs

Example: This example creates a timer and returns directly its value.

local timer = timer()
print(timer:__tostring()) --Prints 0s, because we asks it directly


## class hptimer¶

class hptimer
hptimer()

Constructor - the high precision timer

Creates a timer that counts the time from the time of creation

Example: Creates a High precision timer and stops it directly. Then the time will be displayed in the console.

local timer = hptimer()
print(tostring(timer:stop())) --Prints 0s, because we stop it directly

reset()

Resets the timer to zero.

Resets the timer to 0

Example: Creates a hptimer and resets it directly. Just to demonstrate.

local timer = hptimer()
timer.reset(); -- Resets the timer to 0
print("Timer reset")

float stop()

Stops the time and returns it

Returns: (number) Time in seconds since the last reset or construction

Example: Creates a hptimer and stops it directly. Then the time will be displayed in the console.

local timer = hptimer()
print(tostring(timer:stop())) --Prints 0 Seconds, because we stop it directly

bool triggered(float time)

Allows to check if a certain amount of time has passed.

Parameters:
• float time: the time that should be passed
Returns: (boolean) if the time passed, returns true, otherwise false

Example: This example creates a hptimer and stops it directly and resets it. Then it prints the time, that was got from timer

local timer1 = hptimer()
local time = timer1:stopAndReset()
print(time) -- prints 0, because we call this directly after we created it.

float stopAndReset()

Stops the timer, returns the time and resets it.

Returns: (number) Time in seconds since the last reset or construction

Example: This example creates a hptimer and stops it directly and resets it. Then it prints the time, that was got from timer

local timer1 = timer()
local time = timer1:stopAndReset()
print(time) -- prints 0, because we call this directly after we created it.

float getTime()

Returns the time in platform specific format. (i.e. Milliseconds since 1/1/1970)

Returns: time
__tostring()

Returns the time that has elapsed since the timer was created as a string.

Returns: a LUA string in this format %gs

Example: This example creates a timer and returns directly its value.

local timer = timer()
print(timer:__tostring()) --Prints 0s, because we asks it directly