Send a custom event
On this page
LESSON 13
Connect two records without making the sender know which record handles a clue.
Sender · bell_sender#
local Script = {}function Script.run(context)
await(EmitEvent("OnCustomEvent", {
topic = "archive_bell", strikes = 3
}))
return true
endreturn ScriptReceiver · bell_listener#
local Script = {}function Script.on_custom_event(event)
if tostring(event.topic) == "archive_bell" then
Log("Archive bell rang " .. tostring(event.strikes) .. " times.")
end
endreturn ScriptCheck OnCustomEvent on bell_listener, then apply both records. Run bell_sender. The log should
show three strikes. Subscribe the receiver only. Emitting the same event again from its own
unguarded handler would cause repeated dispatch.
The dispatcher matches the emitted name. Use OnCustomEvent for this checkbox and carry the
gameplay name in topic. The context also carries eventName. A custom field such as strikes
belongs to your own protocol.
