How to send event streams in different directions depending on some condition
Vuo's Select Input and Select Output are similar to if
/else
or switch
/case
statements.
In the last example in the previous section, events from the Receive Mouse Moves node’s trigger were always blocked at the Hold Value node, and events from the Fire Periodically node’s trigger were always allowed through. Instead of always blocking one trigger’s events and always letting another trigger’s events through, what if you want to switch between the event streams?
Here’s an example with a keyboard control that switches the data-and-event stream that controls a circle’s position. When the user presses the space bar, setting the Select Input node’s Which port to true, the circle is controlled by the Leap Motion device. When the user presses the space bar again, setting the Which port to false, the circle is controlled by the mouse. Whichever data-and-event stream is not controlling the circle at a given time is blocked at the Select Input node.
Instead of taking multiple event streams and picking one to let through, as in the previous example, what if you have a single event stream and want to pick one of several downstream paths to route it to? Below is an example of that. The space bar toggles between two circles. Whichever circle is chosen at a given time is controlled by the mouse. This works because the Select Output node routes the data-and-event stream from Receive Mouse Moves through just one of its output ports at a time.