Nodes and Classes
- Please also see the section on Node Creation.
A HeroEngine world is comprised of many different types of data structures, which define the areas, characters, objects, and other less tangible assets which make up the world. This data is usually stored on Nodes, which have various fields which store the data. The Fields are data structures which hold a piece of information such as a number or a piece of text or other much more complex things such as arrays of enumerated values.
Fields are grouped by placing them into different kinds of classes. Nodes are created based on those classes. For example, a "fountain" node might have fields such as "position" to specify where the fountain is located in a particular area, and "scale" to specify how large it is.
Fields are not assigned directly to Nodes, but are assigned via classes. A class defines (among other things) a particular set of fields. A given field can be in multiple classes.
Nodes are created of a particular class, which becomes the node's base class. Later, other classes can also be added to the node, and it will then have access to any field which is defined in at least one of those classes.
Classes and Fields make up (in part) the Data Object Model or DOM of your game. Nodes make up the Game Object Model or GOM of your game. In addition to the DOM definitions and Nodes your game creates, there are many more definitions and nodes that are part of HeroEngine automatically, and included as part of the MMO Foundation Framework.
When a class is created, it must be specified to be one of a dozen different archetypes. For a complete list, see the section on Archetypes. Examples of Archetypes are:
character. Archetypes are used to specify how the server deals with a particular class, such as what kinds of events it triggers. For example, if the position of an instance is changed, the server knows that it needs to send out position updates to other entities, whereas if a position is changed on some other type of archetype, the server will take different actions.
Adding classes to a node
Further classes can be added to a node (this is called "glomming" a class onto the node). It is not possible to simply add a single field to a node -- to add a field, the field must first be added to a class, which is then added to the node. Or, a field can be added to a class which is already on the node, and the node will then automatically have access to the new field.
There are two different ways to add a class to a node: Via the CLI, or via HeroScript. In the CLI, the MNAC command would be used (MNAC stands for Modify Node, Add Class). In HeroScript, the exposed function
glomClass would be used:
In the CLI:
: MNAC 7 ; apple // Add the "apple" class of fields to node # 7
function Example() sampleNode as noderef // Define a node reference sampleNode = 7 // Specify which node that the noderef references GlomClass("apple", sampleNode) // Add the class of "apple" fields to the node .
There are multiple ways for a field to be associated with a particular class.
- When the class is first defined:
- It can have fields specified at the time of creation
- A class can be specified to have a parent class, which means the new class inherits all fields from the parent (including any fields that the parent has inherited from its own parent(s)).
- After a class has been created:
- New fields can be added to the class
- Other parent classes can be added to it. For example, the MCDAP command stands for Modify Class Definition, Add Parent. This is a CLI command that adds one or more parents to a class.
- If a class's parents have any fields added to them, then the child class(es) inherit the new fields as well.
Creating a new class
When a class is created, it can be created "fresh", or it can be created to inherit information from a parent class.
For example, to create a completely new class, the CLI CCD (Create Class Definition) command can be used:
: ccd "banana", data
In the above example, the class "banana" has been created, of the
Adding fields to an existing class
Fields can then be added to the class, also via the CLI, such as with MCDAF (Modify Class Definition, Add Fields):
: MCDAF "banana"; "color", "length", "tastiness" "freshness"
Creating a class from a parent class
A class can also be created with a parent class, which means that the new class inherits the fields that have been defined for another class. For example, to create an "apple" class that inherits from the "banana" class:
: ccd "apple", data; "banana"
The new "apple" class now contains all of the field definitions that the "banana" class did.
Creating nodes from classes
currentFoodNode as noderef // Define a node reference currentFoodNode = createNodeFromClass("banana") // Create the node currentFoodNode.freshness = 5 // Set a value to the node's "Freshness" field
In the above example,
currentFoodNode has been created of class "banana", which means that "banana" is its base class, and will never change, even if additional classes are later added to the node.
Defining a variable without a node
In HeroScript, it is also possible to define a variable as being a particular class, even if it is not associated with a node.
function Example() classWithoutNode as class banana // This creates a data structure with all of the necessary fields classWithoutNode.freshness = 0 // Set the "freshness" field to 0 .
Nodes with multiple classes
If a node has multiple classes, and some of these classes duplicate a particular field (like the "backpack" and "leather" classes, which might both have a "weight" field), this does not mean the node has duplicate fields -- it still has only one instance of that field. Also, adding additional classes will not change the data in a node's current fields -- it only adds fields that didn't already exist on the node. Fields that already existed and had data in them will not be affected. New fields will be added with a value of NULL.
For more information on parenting, please see the
IS KINDOF explanation under the WHERE command.