Event | CraytaKit
Skip to main content

Event

Functions

Function NameReturn TypeDescriptionTags
Send(...)NoneSend data to all listeners of the eventNone
Listen(Script script, string functionName)NoneListen to this event, calling functionName on script when sentNone
HasBindings()booleanReturn true if this Event is bound to anything, even if its something like "every instance of a script" which would actually resolve to no bindingsNone
GetAllBindings()tableGet a table where each element is a table containing a 'script' variable and a 'function' variable, describing each call that is bound by this eventNone

Overrides

Override NameReturn TypeDescriptionTags
to_stringstringNone

Examples

Send

Sends an event to all listeners of the specific event with any arguments passed into Send.

ExampleScript.Properties = {
{
name = "OnExampleEvent",
type = "event",
tooltip = "Example event to fire",
},
}

function ExampleScript:Send()
self.properties.OnExampleEvent:Send(self:GetEntity()) -- will send the entity this script is on to all scripts that are listening on this event
end

Listen

Tells the script passed into the function call to listen for the event to be fired handling it with the passed in function

function ExampleScript:Listen(event)
event:Listen(self, "OnExampleEventHandler") -- will call "OnExampleEventHandler" on this script when the passed in event is fired
end

-- function that will be called when the event passed into "ExampleScript:Listen" is fired
function ExampleScript:OnExampleEventHandler(entity)
print("I hear you!")
end
© 2024 CraytaKit