Eventu.lua

From Moondust Wiki
Revision as of 20:10, 28 February 2015 by Hoeloe (talk | contribs) (Created page with "[https://dl.dropboxusercontent.com/u/30847069/eventu.lua Download Latest Version] EventU is a library that helps manage events, coroutines and timers in LunaLua. == Installa...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Download Latest Version

EventU is a library that helps manage events, coroutines and timers in LunaLua.

Installation

Place the file eventu.lua into the LuaScriptsLib folder.


How to use

To enable the EventU library for a specific level, add this line to lunadll.lua:

local eventu = loadAPI("eventu");

This will load the EventU API.

Example

local eventu = loadAPI("eventu");
    
function onLoad()
    eventu.setTimer(3, displayWindow, true);
end

function displayWindow()
    windowDebug("This is a window!");
end

This will create a new coroutine that will display a debug window every 3 seconds.

Documentation

Values

These are variables you can access

deltaTime number Contains the time between one update frame and the last. This is useful if you want to manage frame-independent events yourself.
time number The current time of the game in seconds. This is useful for event scheduling, but users should take that this value will keep increasing even when the window is inactive and the game is otherwise frozen.
timeFrozen number The current time the game window has been inactive. If this is non-zero, it should be used to offset any calculations using time. However, deltaTime already accounts for this.
maxDeltaTime number The maximum that deltaTime can be, in seconds, before it considers that the game window is frozen. By default, this is 0.1.

External Use Functions

These are functions you will need to use the library

run function
Runs a coroutine (returns false if the coroutine cannot be run). boolean function

The function to run in the coroutine.

waitSeconds seconds
Halts execution of the current coroutine for the specified number of seconds. (Must be called inside a coroutine) boolean number

The number of seconds to wait.

waitFrames frames
Halts execution of the current coroutine for the specified number of frames. (Must be called inside a coroutine) boolean number

The number of frames to wait.

waitForInput key
Halts execution of the current coroutine until the specified key is pressed. (Must be called inside a coroutine) boolean number

The key to listen for (can use key constants here).

waitSignal name
Halts execution of the current coroutine until the specified signal is given by the signal function. (Must be called inside a coroutine) boolean string

The name of the signal to listen for (can have multiple coroutines listening for one signal).

signal name
Signals to wake up coroutines waiting on the specified signal. nil string

The name of the signal to wake up.

setTimer seconds function repeat
Creates a timer. After the specified number of seconds, the specified function will be run. If repeat is true, this will loop infinitely. nil number

The number of seconds to wait for the timer.

function

The function to run after the timer has finished.

boolean:optional

Should the timer repeat infinitely, or stop after it has finished? By default, this is set to false.

setFrameTimer frames function repeat
Creates a timer. After the specified number of frames, the specified function will be run. If repeat is true, this will loop infinitely. nil number

The number of frames to wait for the timer.

function

The function to run after the timer has finished.

boolean:optional

Should the timer repeat infinitely, or stop after it has finished? By default, this is set to false.

registerKeyEvent key function consume
Creates a key listener. When the specified key is pressed, the specified function will be run. If consume is true, this will only occur the first time the key is pressed. nil number

The key to listen for (can use key constants here).

function

The function to run after the key is pressed.

boolean:optional

Should the event occur any time the key is pressed, or only the first time? By default, this is set to false.


Internal Use Functions

These are functions that the library uses to function, but are not necessary for the user

onInitAPI
Registers the API events. nil
init
Initialises the library. nil
update
Updates the library each frame. nil
onKey
Updates key presses. nil