Jump to: navigation, search

VAR <variable> = <expression>

Define a variable

Please also see Defining Variables.


A variable name
A function or other Expression which returns a value


The VAR command is a short-hand way of defining a variable. The variable's type is implied by whatever is assigned to it at creation, and then that type becomes its permanent type. As with any variable, the type can never change.

For example, a standard (non-VAR) way of defining a variable is as follows:

  bob as NodeRef of Class Thingy = othernoderef

If, however, othernoderef was already of class Thingy, then bob could be defined with the VAR command:

  var bob = othernoderef

This would then create bob, which would automatically be of the type NodeRef of Class Thingy. This results in less typing. Another major advantage is that if the noderef's type is changed at some point upstream (such as to a different class), then the bob variable type automatically adapts, without having to modify any variable definitions in the script -- it just needs to be recompiled.

Another very useful aspect of the VAR technique, is when setting a variable equal to a field of a node. This way, if the field's data type is later changed, the associated script variable will automatically change to match the same type, the next time that the script is compiled.

VAR n = returnNode()



  var backpackref = CreateNodeFromClass("container")
  var a = 7     // declares a variable named "a" of type int
  var b = 3.5   // declares a variable named "b" of type float
  var n = GUIref17
  n.visible = true
  var name = "bob"
  var endTime = SYSTEM.TIME.NOW + 0:0:5
  var temp = me.exampleField
  var vis = playerutils:GetMyVisibleCharacter(playerutils:GetMyChar(me))
  // same as vis as NodeRef of Class _CharacterAppearance = ...
  newNode as noderef of class thingie = ReturnNode()
  vis = newNode     // Will generate an error if the node pointed to by newNode is not of class _CharacterAppearance

For more information, please see the section on Defining Variables.

Personal tools