User Tools

Site Tools


class-info

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
class-info [2026/02/23 17:08] polymorphgamesclass-info [2026/02/23 17:59] (current) polymorphgames
Line 1: Line 1:
 ====== Class Info ====== ====== Class Info ======
 +
 +This is a table defining a custom class to be registered with the ''[[:mod-management-functions#registerClass|mod:registerClass()]]'' function.
  
 <code lua> <code lua>
-local MY_ASSET_OBJECT = +
-    TypeName = "MY_ASSET_OBJECT", +    TypeName = "MY_TYPE_NAME", 
-    DataType = "ASSET",+    ParentType = "ASSET",
     Properties = {     Properties = {
         { Name = "Property1", Type = "string", Default = "SomeString" },         { Name = "Property1", Type = "string", Default = "SomeString" },
         { Name = "Property2", Type = "list<RESOURCE_QUANTITY_PAIR>" },         { Name = "Property2", Type = "list<RESOURCE_QUANTITY_PAIR>" },
-        { Name = "Property3", Type = "integer", Default = 1 }+        { Name = "Property3", Type = "integer", Default = 1, Flags = { "SAVE_GAME"}
     }     }
 +    
 } }
- 
-mod:registerClass(MY_ASSET_OBJECT) 
 </code> </code>
 +
 +^ Name ^ Type ^ Description ^
 +| ''TypeName'' | ''string'' | the name of your type |
 +| ''ParentType'' | ''string'' | optional, the name of the parent type of your type\\ Can be a core type such as ''ASSET'', ''COMPONENT'', or any extendable type.\\ If this field is missing, the new type will be a basic data type.  |
 +| ''[[:class-info#Properties|Properties]]'' | ''list'' | a list of the properties your type contains |
 +
 +===== Properties =====
 +A list of the class properties. Each property is defined with a table with the following fields:
 +
 +^ Name ^ Type ^ Description ^
 +| ''Name'' | ''string'' | the name of the property |
 +| ''Type'' | ''string'' | the type of the property.\\ You can define properties based on the basic [[data-types|data types]] (i.e. string, integer, float, etc.) or based on any of the existing [[api#data_classes|DATA]] or [[assets|ASSET]] objects, as well as ''list''s. |
 +| ''Default'' | property type | optional, the default value assigned to the property |
 +| ''[[:class-info#Property Flags|Flags]]'' | ''list<string>'' | optional, additional flag for the property, such as ''SAVE_GAME'' or ''ALLOW_NULL'' |
 +
 +===== Property Flags =====
 +^ Name ^ Description ^
 +| ''SAVE_GAME'' | Flag the property as persistant across reload |
 +| ''ALLOW_NULL'' | Allow the property to be declared ''nil'' without triggering an error |
 +
class-info.1771884518.txt.gz · Last modified: 2026/02/23 17:08 by polymorphgames

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki