Class level assignment

From HEWIKI
Revision as of 14:25, 20 June 2011 by HE-NICK (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

When declaring a node, what is actually being done is declaring a pointer to a node, or a Node Reference (node ref).

As noted elsewhere, each node can have multiple classes. And each class can have its own fields, with data in those fields. So, under some circumstances, it may be desired to copy the value of the fields from one node to another. This can be done, at the class level. In other words, it is possible to copy the values of only some of the fields, but not all of them.

For example, assume there are two classes called weapon and defenseitem. Both of these classes inherit fields from the item class.

The item class has 5 fields:

The sword class inherits from item and therefore has fields a-e. It also has 3 fields of its own, xxx, yyy, zzz.


It might be desired to copy only the sword-specific field data, and not all of the item data as well. Or, it might be desired to copy only the item-specific data, and not the sword data.

In this example, the item-specific data (only a-e) is being swapped between a sword and a shield.

               //
  temp as class item   
             // Not a noderef, temp is simply a local holder variable of class "item"
 
  sword as noderef of class weapon  
             // sword is a pointer to a node of class "weapon" which inherits
             // from "item" and has its own fields.
 
  temp = sword.item   
             // This sets the local variable "temp"'s fields a-e to the same
             // values as sword's a-e.
 
  shield as noderef of class defenseitem  
             // shield is a pointer to a node of class "defenseitem" which 
             // inherits from "item" and has its own fields.
 
 
  sword.item = shield.item
             // This copies the shield's fields a-e to the sword's a-e
 
  shield.item = temp
             // This copies the temp class's a-e fields to the shield

Or the above could be shortened to:

  //
 
  sword as noderef of class weapon  
  var temp = sword.item  
 
 
  shield as noderef of class defenseitem  
             // shield is a pointer to a node of class "defenseitem" which 
             // inherits from "item" and has its own fields.
 
 
  sword.item = shield.item
             // This copies the shield's fields a-e to the sword's a-e
 
  shield.item = temp
             // This copies the temp class's a-e fields to the shield

See also

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox