Node creation

From HEWIKI
Jump to: navigation, search

There are two ways to create nodes: Via the CLI or via HeroScript. In either case, a node can only be created if a class has first been defined in the DOM. New classes can only be defined via the CLI or via the DOM Editor.

Nodes can be created new, or they can be created based on a pre-existing prototype.

For more information, please see the sections on:


Contents

CLI Node Creation

For example, when the world was new and classless, suppose that a GameMaster wishes to create a node (for the sake of this example, let's call it a shrubbery). But they can't create a node until they have a class to define it from. A class specifies which fields will be on the node. A single field can be in multiple classes, or new fields can be defined.

Necessary steps before the node can be created are:

Important: This example is only in the case of a world that does not yet have any classes or fields defined. In practice, there will already be approved classes and fields, and so a script (or developer) will simply need to create the node based on the appropriate class, and not take the additional preliminary steps.

To define a class, first it is necessary to decide which of the Archetypes that the class will be created from. Fields are then defined and added to the class. After the definitions in the DOM are complete, a node of class "shrubbery" can then be created in the GOM.

So first, the "shrubbery" class must be created (defined). A class can only have one Archetype. In the case of a shrubbery, this would probably be an "asset" class.

Create Class Definition

: /CCD "shrubbery", asset

Next, we might wish to define the shrubbery's age, such as: seedling, sapling, full_grown, dead. To do this, a field would have to be defined with certain enumerated values. In the case of an enumeration, before the field could be created, its values would first need to be defined.

Create Enumeration Definition

: /CED "shrubbery_age_states" ; "seedling" "sapling" "full_grown" "dead"

Next, an actual field would need to be declared.

Create Field Definition

: /CFD "shrubbery_age", ENUM "shrubbery_age_states"

Then the original class definition of "shrubbery" could be modified to include the new field:

Modify Class Definition, Add Field

: /MCDAF "shrubbery"; "shrubbery_age"

To display the current state of the class, a Show command would be used:

Show Class Definition

: /SCD "shrubbery"

SCD LISTBEGIN 1 : "Class Definition ID: 1 Name: "shrubbery", Archetype: asset Description: """
SCD LISTELEMENT 1 : "Field ID: 3 Name: "shrubbery_age" Description: """
SCD LISTEND 1: "End of List."

And finally, a node could be created based on the class definition:

Create Node From Class

: /CNFC "shrubbery"

CNFC OK 4 : "Created node ID: 4"

Further fields could then be defined and added to the class, and the node would automatically incorporate them. Additional classes could also be added (glommed) to the node, and it would then have access to any of the fields in those classes. The node's base class, however, will always be "shrubbery".

HeroScript Node Creation

To create a node via HeroScript, one of the following external functions must be used:

Before this can take place though, a class must have already been created in the DOM (see the above section). If the class has already been created, a node can then be created as follows:

Example: Creating a Node via HeroScript

The following function creates a new GOM node, of the DOM class "shrubbery", and assigns it to the node reference variable NewNode.

function CreateNode()
  NewNode as noderef
 
  NewNode = createNodeFromClass("shrubbery")
.

This could also be shortened as follows:

  NewNode as noderef = createNodeFromClass("shrubbery")

Associating Nodes

Note that when creating a node, it is also necessary to create a way to find that node in the future, via some sort of association. If this is not done, then the node may (if it's persistent) still manage to get saved to the database, but without an association, it will never again be loaded into the world, since it's not connected to anything in the world! Nodes are only loaded into the game if they have a hard association to something else that is being loaded, such as a player or area.

Like Classes and Fields, Associations are also defined in the DOM. Please see the section on Associations for more information on associating a node with an area.

Example: Creating Node Associations

For the following code to work, certain classes and associations must have already been created via the CLI:

public function Initialize()
 
  swordref as noderef = CreatePersistedNodeFromClass("thingie")       // Create sword node reference
  backpackref as noderef = CreatePersistedNodeFromClass("container")  // Create backpack node reference
 
  AddAssociation(me, "wearing", backpackref)              // Put the backpack on a player
  AddAssociation(me, "base_hard_association", backpackref) // Make a hard association so it saves
 
  AddAssociation(backpackref, "in", swordref)             // Put the sword in the backpack
  AddAssociation(backpackref, "base_hard_association", swordref) // Make a hard association so it saves
 
  MsgArea("Associations created.")
.

Deleting Nodes

As with creation, nodes can be deleted either via the CLI, or via HeroScript. When a node is deleted, regardless of whether it is deleted via HSL or the CLI, all of its associations are deleted at the same time. Important: If you delete a root node, all of the target nodes that are associated with it via a hard association are also deleted.


CLI Deletion

Delete Node

: /DN 4

HeroScript Deletion

The exposed function DestroyNode is used to delete nodes via HeroScript.

function DeleteTheNode(Byebyebye as noderef)
  DestroyNode(Byebyebye)
  MsgArea("The deed is done.")
.


See also

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox