This is an old revision of the document!
Table of Contents
BUILDING_FUNCTION classes are registerable types in Foundation that define the function a.
For reference all available BUILDING_FUNCTION classes can be found in this section of the API.
Creating & Using a Custom BUIDING_FUNCTION
Step 1: Defining an BUILDING_FUNCTION Class using a Lua Table
To create a custom BUILDING_FUNCTION class 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 BUILDING_FUNCTION object will contain.
local MY_BUILDING_FUNCTION = { TypeName = "MY_BUILDING_FUNCTION", DataType = "BUILDING_FUNCTION", Properties = { { Name = "Property1", Type = "string", Default = "SomeString" }, { Name = "Property2", Type = "list<RESOURCE_QUANTITY_PAIR>" }, { Name = "Property3", Type = "integer", Default = 1 } } } mod:registerClass(MY_BUILDING_FUNCTION)
Note that BUILDING_FUNCTIONs do not need the SAVE_GAME
flag as their properties are read from their registration on load. As such it is not possible to save runtime data in them directly!
Also remember that you can define properties based on the basic data types (i.e. string, integer, float, etc.) or based on any of the existing DATA or ASSET objects, as well as list
s therof!
Step 2: Registering an Instance of a BUILDING_FUNCTION Class
Note: This also aplies to using vanilla BUILDING_FUNCTION classes!
In your mod's lua code you when you want to register an instance of your new BUILDING_FUNCTION class you will have to use the mod:registerAsset(AssetTable)
method as follows.
mod:registerAsset({ DataType = "MY_BUILDING_FUNCTION", Id = "MY_BUILDING_FUNCTION_INSTANCE", Property1 = "SomeOtherString", Property3 = 5 })
Remember, each unique BUILDING_FUNCTION instance requires an Id that identifies it from other BUILDING_FUNCTIONs 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 BUILDING_FUNCTION Class
When you want to use your new BUILDING_FUNCTION instance in a BUILDING_PART registration you can use the string Id to reference it by name.
mod:registerAsset({ DataType = "BUILDING_PART", Id = "MY_BUILDING_PART", . . . AssetBuildingFunction = "MY_BUILDING_FUNCTION_INSTANCE" })