User Tools

Site Tools


custom-classes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
custom-classes [2020/07/08 10:56] maximecustom-classes [2022/03/29 20:36] (current) – added creacting custom classes guides minotorious
Line 1: Line 1:
-====== Custom classes ======+====== 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. You can define new types with the ''mod:registerClass'' function. This function allows you to create new data types, or extend existing core classes.
Line 7: Line 7:
 You can find more information on on the ''registerClass'' function on the [[mod-management-functions#registerClass|mod management functions page]]. You can find more information on on the ''registerClass'' function on the [[mod-management-functions#registerClass|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**.+===== 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''.
  
-===== Custom components =====+<code lua> 
 +function myCustomTypeInfo:someVirtualFunction(param1, param2) 
 +    self.super:someVirtualFunction(param1, param2) 
 +    ... -- custom additional behavior 
 +end 
 +</code>
  
-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:+===== Custom Components ===== 
 + 
 +For custom types extending ''[[api:component|COMPONENT]]'', you can override some base functions that are automatically called for all components:
   * ''**create**()'': when the component is created   * ''**create**()'': when the component is created
   * ''**init**()'': when the component is initialized in the game   * ''**init**()'': when the component is initialized in the game
Line 27: Line 34:
      
 You can see an example of component definition in the mod Example 02 in ''scripts/component/COMP_ANTENNA.lua'' You can see an example of component definition in the mod Example 02 in ''scripts/component/COMP_ANTENNA.lua''
 +
 +----
 +
 +===== Guides on Custom Classes =====
 +
 +  * [[custom-data|Creating a Custom DATA Object]]
 +  * [[custom-asset|Creating a Custom ASSET Object]]
 +  * [[custom-building-function|Creating a Custom BUILDING_FUNCTION]]
 +  * [[custom-mandate|Creating a Custom MANDATE]]
custom-classes.1594220180.txt.gz · Last modified: 2020/07/08 10:56 by maxime

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki