Table of Contents
Custom Classes
You can define new types with the mod:registerClass
function. This function allows you to create new data types, or extend existing core classes.
When you define a new type, you can assign it functions and properties. Properties are editable, usable in your type'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).
You can find more information on on the registerClass
function on the mod management functions page.
Extendable Classes
Some core types are flagged as Extendable in the documentation. This means an extendable type can be used as parent type when creating a custom type. In addition to new functions, you can override some base functions existing in the parent type, flagged as Virtual function. When extend a virtual function, define a new function for your custom type with the same type and parameters. You can call the parent function using the keyword super
.
function myCustomTypeInfo:someVirtualFunction(param1, param2) self.super:someVirtualFunction(param1, param2) ... -- custom additional behavior end
Custom Components
For custom types extending COMPONENT
, 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