Nodes and Classes

From HEWIKI
Jump to: navigation, search

Welcome  ·  Tutorials  ·  The Engine  ·  HeroScript  ·  HeroBlade  ·  Art  ·  HE Setup  ·  Wiki Help

Please also see the section on Node Creation.

Nodes and Classes are data structures within HeroEngine. Classes are defined in the DOM, and then node instances are created in the GOM, based on those classes.

Contents

Overview

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: data, instance, and 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


In HeroScript:

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
.

Defining Classes

Classes and fields are part of the DOM, and as such, can only be created or modified via the CLI or the DOM Editor.

There are multiple ways for a field to be associated with a particular class.

Creating a new class

Classes are part of the DOM, and can be created via the CLI (Command Line Interface), or via the DOM Editor.

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 data Archetypes.

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

After a class has been defined via the CLI, nodes can be created in HeroScript, based on those 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.

See also

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox