User Tools

Site Tools


custom-classes

This is an old revision of the document!


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.


Custom components

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 created
  • init(): when the component is initialized in the game
  • update(): at each frame
  • onEnabled(): when the component is enabled
  • onDisabled(): when the component is disabled
  • onFinalize(_isClearingLevel): when the component is destroyed, only if it has been initialized
  • onDestroy(_isClearingLevel): when the component is destroyed, after onFinalize

You can see an example of component definition in the mod Example 02 in scripts/component/COMP_ANTENNA.lua

custom-classes.1594220207.txt.gz · Last modified: 2020/07/08 10:56 by maxime

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki