The following code sample registers a handler which deregisters itself and sends an event.
123456789
-- The event arguments should match with the event sended.localfunctionhandler(count,content)print("received:",count,content)CustomEvents:RemoveListener("count-content-event",handler)endCustomEvents:AddListener("count-content-event",handler)-- Sends count-content-event two arguments (a number and a string).CustomEvents:Emit("count-content-event",42,"the content is boring")
Here is another code sample of EventHelper.
1 2 3 4 5 6 7 8 9101112
localAddListener=EventHelper.AddListenerlocalRemoveListener=EventHelper.RemoveListenerlocalfunctionhandler(count,content)print("received:",count,content)-- Use RemoveListener of EventHelper insteadRemoveListener(CustomEvents,"count-content-event",handler)end-- Use AddListener of EventHelper insteadAddListener(CustomEvents,"count-content-event",handler)CustomEvents:Emit("count-content-event",42,"the content is boring")