Actions add a lot of performance friendly game mechanic functionality and are at the core of constructing cool game objects from entities. Actions themselves have their own Lua library “action.command()“ for getting and setting property values and specific actions have direct lua Event calls such as the “function doDamage(..)“
The simplest way to control an action is to use the action.setActionParam(..) and action.getActionParam(..) but all lua actions require an identifier for locating which action to target, this known as the actionID.
To pass data between Lua and actions you must first know the actions ID. Each action added to the object increments the action ID by +1 starting from 0. To get the ID all you need to know is the name of the action and the object ID.
Params:
-- Set the action id to default at -1 for catching errors. actionID = -1; obj = -1; function onInit(objID) obj = objID; end function postInit() actionID = action.getActionID(obj ,"ActionName"); end
You should have noticed that this call was put in the postInit() Event. This is to ensure that all actions on all objects have been created/started before you send any commands.
To change an action property dynamically and to examine a current property we use the action library action.setActionParam(..) and action.getActionParam(..). The commands as with all action commands require the action id and object id. This command requires a string argument pass containing the name of the property to be changed.
-- Set the action id to default at -1 for catching errors. actionID = -1; obj = -1; function onInit(objID) obj = objID; end -- Use the post init to grab the action id function postInit() actionID = action.getActionID(obj ,"PhysX RigidBody"); setParam(); sprint("value: "..getParam()); end function setParam() -- Disable Physics on this object. value = false; action.setActionParam(obj, actionID, "PRB Enabled", tostring(value)); end function getParam() value = action.getActionParam(obj, actionID,"PRB Enabled"); return value; end