[[assets|ASSET]] classes are the basic registerable types in Foundation. For reference all available [[assets|ASSET]] classes can be found in [[api#assets_classes|this]] section of the API. ===== Creating & Using a Custom ASSET Object ===== ==== Step 1: Defining an ASSET Object using a Lua Table ==== To create a custom [[assets|ASSET]] object we will need to make use of the ''mod:registerClass(AssetTable)'' function providing it with an associated Lua Table. Here you decide what properties your custom [[assets|ASSET]] object will contain. local MY_ASSET_OBJECT = { TypeName = "MY_ASSET_OBJECT", DataType = "ASSET", Properties = { { Name = "Property1", Type = "string", Default = "SomeString" }, { Name = "Property2", Type = "list" }, { Name = "Property3", Type = "integer", Default = 1 } } } mod:registerClass(MY_ASSET_OBJECT) Note that [[assets|ASSET]]s unlike [[api#data_classes|DATA]] do not need the ''SAVE_GAME'' flag as their properties are read from their registration on load! Also remember that 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 therof! ==== Step 2: Registering an Instance of an ASSET Object ==== Note: This also aplies to using vanilla ASSET objects! In your mod's lua code you when you want to register an instance of your new [[assets|ASSET]] object you will have to use the ''mod:registerAsset(AssetTable)'' method as follows. mod:registerAsset({ DataType = "MY_ASSET_OBJECT", Id = "MY_ASSET_OBJECT_INSTANCE", Property1 = "SomeOtherString", Property3 = 5 }) Remember, each unique [[assets|ASSET]] instance requires an Id that identifies it from other [[assets|ASSET]]s of the same class. In case you omit any properties you don't yet need to explicitly set they will use their default values. As we have done with ''Property2'' above. ==== Step 3: Using an Instance of an ASSET Object ==== When you want to use your new ASSET instance be it in a [[api/component|COMPONENT]] property, [[api/building_function|BUILDING_FUNCTION]], or other [[assets|ASSET]]/[[api#data_classes|DATA]] class you can use the string Id to reference it by name. For example here we are using our custom [[assets|ASSET]] instance as the default value in a [[api/component|COMPONENT]] local COMP_EXAMPLE = { TypeName = "COMP_EXAMPLE ", ParentType = "COMPONENT", Properties = { { Name = "Property1", Type = "MY_ASSET_OBJECT", Default = "MY_ASSET_OBJECT_INSTANCE" } } }