Reset Constants

Nodes have three properties that are significant to understanding how constants work:

  • Definition
  • Calculated value
  • Evaluation flag

See About Nodes.

When you call a constant, DScript checks the constant's evaluation flag to see if the constant has been evaluated before. If it has not, then the constant's definition is executed, the result is stored in the calculated value property, and the evaluation flag is set to true. The next time you call the constant, the evaluation flag indicates the constant has been evaluated before, so the constant just returns a copy of its stored value.

You can force a constant to clear its value (set equal to null) and reset the evaluation flag using the clear primitive in an expression such as:

clear("Age")

See clear.

Calling clear without an argument causes all constants to be cleared.

You can reset the evaluation flag in all constants using the reset primitive:

reset

See reset.

Note that this does not clear all values attached to a constant. It simply causes the values to be considered invalid.

Reset is much faster than clear because you can reset every node's evaluation flag by incrementing a single global variable. Clear must process every node individually.

See About the Constant Function.