Gly Game Engine 0.0.11
Game engine in lua
Loading...
Searching...
No Matches
Bus

Functions

local function abort ()
 stop current signal
 
local function emit (key, a, b, c, d, e, f)
 send unique event
 
local function trigger (key)
 sender event function
 
local function listen (key, handler_func)
 subscribe event
 

Detailed Description

Warning
This is an advanced API!
only for advanced programmers, You might be lost if you are a beginner.

You can get inspired by some explanations about how the event bus works in the JavaScript framework called Vue, it is very similar, but there is only 1 global bus that the engine itself uses to work.

Event Bus System

broadcasts some event to all nodes.

Event Callbacks (Deep Overview)

The event system is also used to control events from the engine itself, where the core triggers an action and it is propagated to the internal modules, and to the game and its components (nodes).

Function Documentation

◆ abort()

local function abort ( )

This interrupts the signal to the next nodes, this also applies to the engine itself and prevents lifecycle events.

Note
reckless use can lead to bad behavior.
Example
local function quit(std, game)
std.bus.abort()
end

◆ emit()

local function emit ( key ,
a ,
b ,
c ,
d ,
e ,
f  )

broadcast message for all nodes.

Alternatives
  • std.bus.emit_next queue to be sent in the next frame instead of immediately. but it doesn't work for draw event.
Joke
Yes, abcdef is faster to implement and execute. If you need more parameters than that, the problem is in your code.
In fact, love2d also does the same thing.
Example
std.bus.emit('on_shoot', x1, y1, x2, y2)

◆ listen()

local function listen ( key ,
handler_func  )
Alternatives
  • std.bus.listen_std receive message after std
  • std.bus.listen_std_data receive message after std and data
  • std.bus.listen_std_engine receive message after std and engine
  • std.bus.listen_all receive message without key topic, because applies to all events.
Example
std.bus.listen('player_death', function()
print('game over!')
end)

◆ trigger()

local function trigger ( key )
Example
love.filedropped = std.bus.trigger('file_dropped')