EventU.lua

From Moondust Wiki
(Redirected from Eventu.lua)
Jump to navigation Jump to search

Attention: This page contains dead links!

Download Latest Version

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

Installation

Place the file eventu.lua in either your level's custom graphics folder for use in a level, along with a lunadll.lua file, or in the same directory as your .wld file along with a lunaworld.lua file for use throughout an entire episode.

How to use

To enable the EventU library, add this line to lunadll.lua:

local eventu = API.load("eventu");

This will load the EventU API.

Example

local eventu = API.load("eventu");
    
function onStart()
    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), returns the coroutine object as a second argument. boolean, Coroutine 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).

waitEvent name
Halts execution of the current coroutine until the specified SMBX event is called. (Must be called inside a coroutine) boolean string

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

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. Coroutine 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.

setTimer seconds function repeatCount
Creates a timer. After the specified number of seconds, the specified function will be run. The timer will be run repeatedly the number of times given in the repeatCount variable. Coroutine number

The number of seconds to wait for the timer.

function

The function to run after the timer has finished.

number

The number of times the timer should repeat.

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. Coroutine 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.

setFrameTimer frames function repeatCount
Creates a timer. After the specified number of frames, the specified function will be run. The timer will be run repeatedly the number of times given in the repeatCount variable. Coroutine number

The number of frames to wait for the timer.

function

The function to run after the timer has finished.

number

The number of times the timer should repeat.

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. Coroutine 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.

registerSMBXEvent event function repeat
Creates a SMBX event listener. When the specified SMBX event is called, the specified function will be run. If repeat is true, this will occur any time the event is called, rather than just the first time. Coroutine string

The event to listen for.

function

The function to run after the event is called.

boolean:optional

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

breakTimer
Cancels an infinitely repeating timer or event after the function has finished executing. (Must be called inside a coroutine) nil
pauseTimer timer
Pauses a coroutine waiting for frames or seconds until resumeTimer is called. Also works for timers created with setTimer or setFrameTimer. Has no effect otherwise. nil Coroutine

The waiting coroutine to pause.

resumeTimer timer
Resumes a coroutine paused using pauseTimer. Has no effect if the timer is not paused. nil Coroutine

The paused coroutine to resume waiting.

getTimer timer
Gets the number of seconds or frames remaining until a waiting coroutine resumes. Returns 0 if the coroutine is not waiting. number Coroutine

The waiting coroutine to get.

abort coroutine
Cancels a coroutine that is currently waiting. nil Coroutine

The coroutine to cancel.

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