This is an old revision of the document!
Components
Components are small modules used to define the behavior of any game object. Game objects can have any number of components, but can have only one of each type.
See the list of all available components.
You can define new types of components with the mod:registerClass
function.
When you define a new component type, you can assign it properties that are editable, usable in your component's behavior, and that can be saved in a savegame. Those properties must have a name and a type. They can also have a default value, flags, and access functions (getter and setter).
Components can also have functions. In addition to new functions, you can override some base functions that are automatically called for all components:
create()
: when the component is createdinit()
: when the component is initialized in the gameupdate()
: at each frameonEnabled()
: when the component is enabledonDisabled()
: when the component is disabledonFinalize(_isClearingLevel)
: when the component is destroyed, only if it has been initializedonDestroy(_isClearingLevel)
: when the component is destroyed, afteronFinalize
You can see an example of component definition in the mod Example 02 in scripts/component/COMP_ANTENNA.lua
Components can be added to any FBX node with the mod:registerPrefabComponent
function.
- mod.lua
mod:registerPrefabComponent("models/MithrilFactory.fbx/Prefab/MithrilFactory/ExtensionB/RootPart", { DataType = "COMP_DIRT_RECTANGLE", Size = {8, 8} })
See mod Example 02 for more examples.