Register trigger event function (call chain)||doc135695

September 20, 2022

Format

 Trigger.addHandler(cfg, name, handler)
  • The class to which the function belongs:Trigger

Description

Add the processing callback function (call chain) of the template trigger event, bind the user-defined function to the event name, and call all the processing functions bound to the event when the event is triggered. The first parameter of the processing function is Contextual information when the event is triggeredcontext


Precautions

  • andRegisterHandlerDifferent, the handler function registered by this function exists in the form of a call chain. When the event is triggered, the handler function bound to the event will be triggered in turn.

Parameters

Variable name type Description
cfg config The configuration information of the object template that needs to trigger the event
name string event name
handler function handle callback function


Value Returned

type Description
function Cancel the function that handles the callback


Code Samples

local cancelFunc = Trigger.addHandler(Entity.GetCfg("myplugin/player1"), "ENTITY_ENTER", function(context)
    local player = context.obj1
    print(player.name .. "enter game!")
end)