Prop.setCallback ▲ 12

Available from Easy Red 2 2.1.1

Listens to an event from the script of the prop. It takes the same event names as er2.setCallback (phase_changed, objective_captured, battle_ended...) and the function receives the same parameters, but every prop keeps its own function. er2.setCallback holds a single function per event for the whole battle, so with it a second prop would replace the first.The function is called wherever the script of the prop runs, whether or not the prop is loaded at that moment.


Return value

Return TypeDescription
voidTrue if the callback was registered.

Parameters

ParameterTypeDescription
1stringName of the event, for example objective_captured.
2functionCalled with the parameters of that event. Setting the same event again replaces the function of this prop only.

Examples

A flag that follows its objective

-- on a flag prop: it shows the flag of whoever holds the objective it stands in
myself:setCallback("objective_captured", function(objective, faction)
    if objective:isInside(myself:getPosition()) then
        myself:setAlbedo(er2.getFactionFlag(faction))
    end
end)

Back to Scripting API