GetEvent||doc136851

September 20, 2022

Format

Event:GetEvent(eventName, space)

Describe

Get the events in the specified space. In most cases, it is not necessary to specify the space. When it is not specified, it defaults to the space of the engine ("engine"), so there is no need to pass the second parameter when obtaining the events defined by the engine, that is, event:getevent ("someevent") is equivalent to event:getevent ("someevent", "engine"). In a few cases, the two systems may just share the same event name, but the trigger timing is different, so it needs to be distinguished by namespace. For example, the "jump" event of the level system is to skip the level, and the "jump" event of the AI system is to jump. If the event is not distinguished, the AI system will trigger the jump event, and the level will jump. When this happens, namespaces play a role. When AI system triggers events, it only gets events in its own space to trigger, and so does the level system.

parameter

Variable name Type Describe
eventName string Event name
space string Namespace

Return value

Type Describe
BindableEvent Bindable events

Code example

Bind the global event of player login and print player information.

local bindableEvent = Event:GetEvent("OnPlayerLogin")
bindableEvent:Bind(function(player)
    print("OnPlayerLogin", player)
end)