Represents a trigger property that can fire events and notify listeners.
Unlike other Property types, a trigger does not store a persistent value. It emits an event when fire() is called.
Registers a listener that is invoked when the trigger fires.
Copy
Ask AI
local vmi = context:viewModel()if vmi then local cannon = vmi:getTrigger('cannon') if cannon then cannon:addListener(function() print("cannon fired!") end) cannon:fire() endend
Removes a previously registered listener.
Always remove listeners when they are no longer needed to avoid leaks.
Copy
Ask AI
function init(self: MyNode, context: Context): boolean local vmi = context:viewModel() if vmi then local cannon = vmi:getTrigger('cannon') if cannon then self.cannon = cannon self.onCannonFired = onCannonFired cannon:addListener(onCannonFired) end end return trueendfunction removeCannonListener(self: MyNode) if self.cannon then self.cannon:removeListener(self.onCannonFired) endend
Fires the trigger and notifies all registered listeners.
Copy
Ask AI
local vmi = context:viewModel()if vmi then local cannon = vmi:getTrigger('cannon') if cannon then cannon:addListener(function() print("cannon fired!") end) cannon:fire() endend