Brainevents

Brainevents activate gameplay features and logic in a sequential order that is determined by the object or player action. See more at the Brainevents documentation page.

Function Description
addBrainEventCallback(name, function)

Adds a callback function to trigger when the Brainevent is triggered. An event can only have one callback attached to it at a time. If addBrainEventCallback() is used on an event that already has a callback, it will replace the existing one with the new one.

currentEvent()

Returns the name of the current or most recent event. If there is no such event, returns an empty string.

hasEvent(name)

Returns true if the entity has an event of the given name, or false if not.

removeBrainEventCallback(name)

Removes the callback attached to the given Brainevent. Remember, each event can only have one callback associated with it.

setEvent(name)

Triggers the event passed as a parameter, also setting it as the entity’s current event. If no data is passed, the event will pass a boolean true value.


addBrainEventCallback(name, function)

Adds a callback function to trigger when the Brainevent is triggered. An event can only have one callback attached to it at a time. If addBrainEventCallback() is used on an event that already has a callback, it will replace the existing one with the new one.

Parameters

string name – the name of the event function the callback function to execute when the event is triggered

if (this.entity().hasEvent('MyEvent')) {
    this.entity().addBrainEventCallback('MyEvent', function() {
        log('In MyEvent Callback!');
        return true;
    });
}

↑ Back to top


currentEvent()

Returns the name of the current or most recent event. If there is no such event, returns an empty string.

Returns

string – the name of the current event

↑ Back to top


hasEvent(name)

Returns true if the entity has an event of the given name, or false if not.

Parameters

string name – the name of the event

Returns

boolean – true if the entity has the event, false if not

↑ Back to top


removeBrainEventCallback(name)

Removes the callback attached to the given Brainevent. Remember, each event can only have one callback associated with it.

Parameters

string name – the name of the event

↑ Back to top


setEvent(name)

Triggers the event passed as a parameter, also setting it as the entity’s current event. If no data is passed, the event will pass a boolean true value.

Parameters

string name – the name of the event
data (optional) value passed to the event of data type boolean, number, or string

this.entity().setEvent('AttackEventName');

↑ Back to top