Custom Scripts

Load.lua and Start.lua

Load.lua and Start.lua should be located in the data folder, along with any custom script files.

Load.lua is ran once before startup, and everytime a script reload is triggered with CTRL + R.

Start.lua is ran once after Load.lua, but not after each reload.

Custom Scripts

To register a custom script definition for adding to entities, use Script.register.
Script registering is done within Load.lua as to allow for re-registering of scripts on reload.

Inside Load.lua

Script.register("MyScript", "MyScript.lua")

To add a custom script instance to an entity, add a script component, and use script:create to create an instance of the script.
An entity's Script component can hold up to 8 instances of any type.

Inside Start.lua

local entity = Entity.create()


Each custom script instance is created with an Entity object referencing the entity it was created upon.
The entity object is allocated to self.entity and custom scripts should add, check, and get components through this entity object.

Inside MyScript.lua

local MyScript = {}

function MyScript:load()
    -- called on creation


    self.transform = self.entity:get(Transform)

function MyScript:reload()
    -- called on script reload

function MyScript:update()
    -- called every tick

return MyScript

Script Reloading

Script reloading recompiles every custom script file registered using Script.register without restarting.
Script reloading is triggered with CTRL + R.

The reload function is triggered in every custom script after reloading, before update.