Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Variables and namespaces

 

As you have seen above, you can easily access variables by writing their name (including $ prefix) in an expression. Namespaces define in which cue the variables are actually stored (and from which cue they are read).

...

Creating and removing variables

 

You can create variables with certain actions and conditions, such as the <set_value> action:

...

The default operation of <set_value> is “set”, but there are more: “add”, “subtract”, and “insert”. add and subtract change the value of an existing variable, which is created as 0 if it didn’t exist before. If neither min, max nor exact attribute is provided, an exact value of 1 is assumed. 

<set_value name="$foo" operation="add" />

The trick is that <set_value> not only works on variables, but also on list elements:

 

<set_value name="$list.{1}" exact="42" />

The operation insert is special, and it only works on lists. It inserts the value at the specified position (note that the position beyond the last element is also valid here):

 

<set_value name="$list.{1}" exact="42" operation="insert" />

...

Appending is easier than that. The following actions are equivalent:

 

<set_value name="$list.{$list.count + 1}" exact="42" operation="insert" />
<
append_to_list name="$list" exact="42" />

...

To remove variables or list entries, use <remove_value>:

 

<remove_value name="$foo" />
<
remove_value name="$list.{1}" />

...

Accessing remote variables

 

You can also read and write variables in other cues by using the variable name as property key: 

<set_value name="OtherCue.$foo" min="0.0" max="1.0" />
<
set_value name="md.OtherScript.YetAnotherCue.$bar" exact="OtherCue.$foo" />

Instead of referencing a cue by name, you could also reference it via a keyword or another variable: 

<set_value name="static.$counter" operation="add" />
<
set_value name="parent.$foo" exact="42" />
<
set_value name="this.$bar" exact="parent" />
<
set_value name="$baz" exact="this.$bar.$foo" />


Namespaces

 

In the examples above, a variable was written to and read from the “this” cue. This can be necessary: the expression “$foo” may be different from the expression “this.$foo”. The reason for that are namespaces.

Consider this case: 

<cue name="Root">
  <
actions>
    <
set_value name="$foo" />
  </
actions>
  <
cues>
    <
cue name="SubCue"> [...]
    </
cue>
  </
cues>
</
cue>

...

Defining a cue’s namespace

...

When writing a cue, you can specify what the namespace of the cue should be, by adding the namespace attribute. The following values are possible:

 

  • this: Use “this” cue as namespace, even for instances: $foo == this.$foo

  • static: Same as “this”, but when instantiated, use the static cue: $foo == static.$foo

  • default: The namespace is inherited from the parent cue. The default for root cues and for libraries is the same as “static”.

 

 

 


Warning

Although in general the expression “$foo == namespace.$foo” is true, there is one exception: When library parameters are evaluated in the referencing cue, variables are resolved using the parent’s namespace. However, the referencing cue creates a new namespace, so the namespace keyword already points to the library, not to the parent’s namespace. Example:

<cue name="LibRef" ref="Lib">
  <
param name="Param1" value="$foo" /> <!-- $foo from parent namespace -->
  <
param name="Param2" value="namespace.$foo" /> <!-- LibRef.$foo (error) -->
</
cue>

 

...