Creating a new class
Note
This document is a work in progress and incomplete.
Creating a new class is fairly simple.
To start, create a Lua script at the correct location depending on what you wish your classname to be. See Classnames for information on how the game handles classnames internally and how you should name and organise your classes.
For this example, we’re creating a class simply named MyClass. This will be a simple class that has a configurable mesh and prints an incrementing number to the debug console when interacted with by Raz.
Class Constructors
Class constructors are simply functions. The name of the function must exactly match the name of the entity’s file and is case-sensitive.
Constructors take one argument, traditionally called Ob and must return this back when done. At the start of the function the constructor should check if Ob is nil, and if it is not should use CreateObject() to create it.
1function MyClass(Ob)
2 if ( not Ob ) then
3 Ob = CreateObject("ScriptBase"); --Inherit directly from ScriptBase
4 end
5
6 return Ob; --ALWAYS be sure to return Ob!
7end
Above is an example of the most simple class constructor possible. This class is spawnable ingame but will do nothing and won’t appear as anything in the world.