Package openmw_aux.time
openmw_aux.time defines utility functions for timers.
Implementation can be found in resources/vfs/openmw_aux/time.lua.
Usage
local time = require('openmw_aux.time')
Type time
| time.GameTime | |
| time.SimulationTime | |
| time.day | |
| time.hour | |
| time.minute | |
| time.newGameTimer(delay, callback, arg, callbackArg) |
Alias of async:newSimulationTimer ; call callback(arg) in |
| time.newSimulationTimer(delay, callback, arg, callbackArg) |
Alias of async:newSimulationTimer ; call callback(arg) in |
| time.registerTimerCallback(name, func, fn) |
Alias of async:registerTimerCallback ; register a function as a timer callback. |
| time.runRepeatedly(fn, period, options) |
Run given function repeatedly. |
| time.second |
Type time
Field(s)
- #string time.GameTime
- #string time.SimulationTime
- #number time.hour
- #number time.minute
- time.newGameTimer(delay, callback, arg, callbackArg)
-
Alias of async:newSimulationTimer ; call callback(arg) in
delaygame seconds.Callback must be registered in advance.
Parameters
-
#number delay: -
openmw.async#TimerCallback callback: A callback returned byregisterTimerCallback -
arg: An argument forcallback; can benil. -
callbackArg:
-
- time.newSimulationTimer(delay, callback, arg, callbackArg)
-
Alias of async:newSimulationTimer ; call callback(arg) in
delaysimulation seconds.Callback must be registered in advance.
Parameters
-
#number delay: -
openmw.async#TimerCallback callback: A callback returned byregisterTimerCallback -
arg: An argument forcallback; can benil. -
callbackArg:
-
- time.registerTimerCallback(name, func, fn)
-
Alias of async:registerTimerCallback ; register a function as a timer callback.
Parameters
-
#string name: -
#function func: -
fn:
Return value
-
- time.runRepeatedly(fn, period, options)
-
Run given function repeatedly.
Note that loading a save stops the evaluation. If it should always work, call it during the initialization of the script (i.e. not in a handler)
Parameters
-
#function fn: the function that should be called -
#number period: interval -
#table options: additional optionsinitialDelayandtype.initialDelay- delay before the first call. If missed then the delay is a random number in range [0, N]. Randomization is used for performance reasons -- to prevent all scripts from doing time consuming operations at the same time.type- eithertime.SimulationTime(by default, timer uses simulation time) ortime.GameTime(timer uses game time).
Return value
#function: a function without arguments that can be used to stop the periodical evaluation.
Usages
local stopFn = time.runRepeatedly(function() print('Test') end, 5 * time.second) -- print 'Test' every 5 seconds stopFn() -- stop printing 'Test' time.runRepeatedly( -- print 'Test' every 5 minutes with initial 30 second delay function() print('Test2') end, 5 * time.minute, { initialDelay = 30 * time.second })local timeBeforeMidnight = time.day - core.getGameTime() % time.day time.runRepeatedly(doSomething, time.day, { initialDelay = timeBeforeMidnight, type = time.GameTime, }) -- call `doSomething` at the end of every game day.
-
- #number time.second