Soldier.setCallback 54

Register a callback for a specific event Id on a specific Soldier. Only a callback can be tied to an event Id, so when this is called again on the same Id, the new callback reference will override previous one.
Callback Ids are specified at this page.


Return value

Return TypeDescription
boolTrue if the callback was correctly set on the specific Soldier

Parameters

ParameterTypeDescription
1stringId of the callback (check callback Id database)
2functionFunction that gets called when the callback is triggered

Examples

Example 178

-- Define any Lua function as your callback.
function OnSoldierDie()
    print('Soldier died: ' .. myself().getName())
end

-- spawn a German soldier with leutenant rank at position 0,0,0
local soldier = spawnSoldier(vec3(0,0,0), "Germany_axis", 8, "ger_infantry_tankcrew_leader")

-- Register the OnSoldierDie callback from Lua.
soldier.setCallback("soldier_died", OnSoldierDie)

Back to Scripting API