aSignals

Description

Event Bus 🔗

SIGNAL : LISTEN : CONDITIONAL 🔗

These functions are for signalling and listening for event triggers. Basically it's a way of your code being able to tell the whole game what just happened, such as if a player did some action, or some other event happened. Note that this is more for games than for general modding, but is a helpful API regardless.

This is a global set of functions that do what they say on the tin mostly. The exception is CONDITIONAL which is a bit more involved (see below). Signals and listeners not only allow you to sometimes save on constant checks by using one-off events instead, but you can also allow extending, avoid some dependencies, and generally make things more reactive and less constant polling. Instead of checking constantly whether the player has just died and then come back to life, we use core.register_on_respawnplayer. This is no different except it is generalised and you can signal whatever thing you want.

Example Use 🔗

LISTEN("on_player_damage", function(player, damage, source)
    core.chat_send_all(
        "Player "..player:get_player_name()..
        " was hit for "..damage.." HP"
    )
end)

LISTEN("can_player_take_damage", function(player, damage, source)
    if player:get_meta():get_string("invulnerable") == "true" then
        return false
    else
        return true
    end
end)

if CONDITIONAL("can_player_take_damage", player, damage, source) then
    SIGNAL("on_player_damage", player, damage, source)
end

You can also get type and autocomplete hints using the below:

---@param a number
---@param b string
---@diagnostic disable-next-line: duplicate-set-field
function SIGNAL.on_something_happen:signal(a, b) end -- doesn't actually change the function, just for hints/autocomplete
SIGNAL.on_something_happen:signal(a: number, b: string) -- now gives type hints

Any more details can be found within the code itself, as it is documented in-line so it shows examples in the autocomplete.

Reviews

Review

Do you recommend this mod?

  • No reviews, yet.

Releases

2026-04-09

Download

2026-04-09 10:32 UTC

2026-04-09 🔗

  • moved to metatable / object based
  • you can now "define" the callback signature, like function(string, table, number) for autocomplete and type hints (see docs)
  • indexing SIGNAL.on_my_event will create it if it is not yet present
  • no more returning a string to "free" the callback / deregister it, just return true as a second return argument (string returns will be ignored)
All releases

Threads

New thread

Thread Last Reply

No threads found

Information

Provides

asignals

Dependencies

Required
No required dependencies

Information

Type
Mod
Technical Name
asignals
Languages
English
License
0BSD
Maintenance State
Maintenance Only
Added
2024-11-23 09:30 UTC
Maintainers
Sumi