Register trigger event function (call chain)||doc135695

September 20, 2022


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


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


  • 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.


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( .. "enter game!")