AddEventHandler

From Wiki G1R-MP G1 Remake Multiplayer
Revision as of 12:43, 4 August 2026 by QCherry (talk | contribs) (Automatyczna aktualizacja dokumentacji funkcji)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

addEventHandler

Attaches a Lua callback to a named event in the current resource.

Syntax

bool addEventHandler(string eventName, element attachedTo, function handler)

Parameters

Name Type Required Description
eventName string yes The event to listen for.
attachedTo element yes The attachment target. Use root for a global resource handler.
handler function yes The callback invoked when the event is triggered.

Returns

Returns true when the handler is registered; otherwise returns false.

Examples

Handle a custom event:

addEvent("quest:updated")

local function onQuestUpdated(questId)
    print("Quest updated:", questId)
end

addEventHandler("quest:updated", root, onQuestUpdated)

Notes

  • Available in both client-side and server-side resource scripts.