Kanzi Engine Lua API is a platform-independent interface to the Kanzi Engine using the Lua programming language. It allows you to create application and user interface logic in Kanzi Studio.
When you export a kzb file, Kanzi Studio embeds Lua scripts in the kzb file.
Kanzi uses Lua 5.4. See https://www.lua.org/manual/5.4/.
To execute a Lua script, in a node, create a trigger with which you want to execute the script, and in the trigger create a Run Lua Script action. In the Run Lua Script action, set the script file that you want to execute when the trigger is set off.
In Kanzi documentation, see:
When you set off a trigger that executes the Run Lua Script action, the action assigns to the contextNode variable the reference to the node that contains the trigger.
When accessing nodes from a Lua script, Kanzi automatically deduces their type and provides the instance of the correct type. For example, if your trigger is attached to a Text Block 2D node, contextNode is an instance of the TextBlock2D class.
To navigate the node tree, start with the contextNode variable, then use the lookupNode function with either relative path or an alias in the nearest resource dictionary.
To acquire resources, use the Node.tryAcquireResource function.
To set and get property values of Kanzi objects, use the KanziObject.getProperty and KanziObject.setProperty functions.
To enumerate and modify nodes in the node tree, use the functions in the Node2D and Node3D classes.
To instantiate prefabs and attach instantiated nodes to the node tree, use the functions in the PrefabTemplate class.
You can use Kanzi math types in your Lua scripts. See ColorRGBA, Vector2, Vector3, Vector4, Matrix3x3, Matrix4x4, Quaternion, SRTValue2D and SRTValue3D.
To dispatch Kanzi messages, use the Node.dispatchMessage function. See MessageArguments and MessageType.
You can define message handlers in a Lua script and add the message handlers to nodes. See Node.addMessageHandler.