Scripting: Referencing Nodes

From Waltz
Revision as of 13:40, 24 July 2019 by Patrick Angle (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Referencing nodes is the core way in which data flows between different nodes. References are shown on the stage as connections between nodes. Connections can be typed manually as well as created automatically for you by connecting nodes on the stage.

To reference a node, you use the special $ object, which refers to the stage as a whole in Waltz. Each node's name is a property on the special $ object. This means the following expression refers to a node named myValue:


you can then access values and functions from that node. For example, to get the touches from an LED Processor Input Node named ledProcessor:


To call a function on a node, like to send a UDP message from a UDP Output Node named greatUdpOutput1:

$.greatUdpOutput1.send("new port, who dis?\n")

Dynamically Referencing Nodes

In some situations, you may want to reference a different node depending on some other state of your show. When you want to reference a node, but the node won't always be the same node, you can use the Map-style bracket notation to reference a node. For example, given a node named myValue, the following two lines reference the same property of that node, namely its value.


This opens up a slew of possibilities, as in the second example the node name is just passed a string into the collection getter.

In a situation where you have four nodes, named myValue1, myValue2, myValue3, and myValue4, you are able dynamically choose which node you reference, like in this example below.

var nodeName = "myValue" + numberFromElsewhere
Expressions and Scripting
Concepts Script Expressions · JavaScript
Fundamentals Constructors · Functions · Grammar · Operations · Outputs · Parameters · Referencing Nodes
Advanced Topics Flow Control · Consumer Functions · Loops and Iterations · Reference Chains
Errors Recursion · Script Exceptions · Syntax Errors · Try and Catch