Walkthrough No. 3
NOTE ! With Release 8.1 Maxon included a new Node in the collection of Xpresso Nodes, called Flipflop. This new node is essentially srek's node described in this Walkthrough but with the addition of a Switch Input Node, and the Output Node renamed from "Bool" to "Out". These three nodes work as in srek's node, and the new node can be inserted in place of srek's node. Therefore this Walkthrough still applies unaltered, (except that it does not discuss the Switch Node). Please see Maxon's file Addendum_81_US.pdf (or the version for your language) supplied as part of Release 8.1.
On Postforum Björn (Srek) has posted several hints and tricks, Xpresso Expressions etc. at his web site. One of these is a Flipflop. This does not do anything visual or exciting - it is a tool, in the form of a Node that you can include in your Xpresso Expressions where needed. It has two Input Ports and one Output Port.
When a Boolean True signal arrives at its On Input Port, its Output Port will provide a Boolean True. Even if the True at the On Input Port returns to False, the True at the Output Port will remain True until a Boolean True signal arrives at its Off Input Port. In other words the output will latch and remain latched until it is unlatched.
The Flipflop is useful when you want your Xpresso Expression to record that an event has happened so that another event, perhaps occurring later during the animation, can make use of that information. For example, you might want a light to be capable of being switched to its on state (by another Node) at a certain point in an animation.
Incidentally, the two icons at the top right corner of a node like Monoflop indicate that it contains several nodes which are packed into one. These can be unpacked if you want to see them but that is not for beginners.
Now lets walk through the above Project file to study a simple demonstration of how Flipflop could be used. Download the above Project file and load it into Cinema. In the Object Manager locate the Null Object. On its right there is an Xpresso Tag. Double click on that and the Xpresso Editor window will open. This reveals the entire Xpresso Expression, one of whose Nodes is Flipflop, accompanied by other Nodes. (An Xpresso Tag can be attached to any Object in the Object Manager - it doesn't matter - but a Null Object is usually most convenient.) If you need to move the whole collection of Nodes within the window to a more convenient position, click and drag the Move Icon: If some of the Nodes are positioned outside the window, make them all fit in by doing Xpresso Editor window > Menu Bar > View > Show All.
None of the yellow Nodes are active. They are of two types: Value Indicators and Remarks. Result Value Indicators display the value currently being produced by a Node or being delivered to a Node, depending on the Port to which the Indicator is Linked. A Spy Indicator simply displays the value being passed between the two nodes to which it is Linked and does not alter that value. Indicators are useful when debugging. (Result and Spy Nodes do not show correct values while the animation is running.) Remark Nodes are there to add helpful information about what is going on. Additional remarks are sometimes included in the Node's Attributes (in the Attribute Manager) revealed after pressing the Basic button.
Let's examine the top Time Node first. Its Output Port produces a value equal to the current frame number of the animation and this is delivered (via the Spy) to the Input 1 Port of the Compare Node. A Compare Node compares the values of the two data items delivered to its two Input Ports. If you select the Compare Node and look at its Attributes (in the Attribute Manager : Basic button) you will see that its Data Type has been set to Integer and its Function to "==" (equals). This means that the Compare Node will output a Boolean True value (1) whenever the value of the data arriving at its Input 1 is equal to the value of the data arriving at its Input 2, otherwise it will output a False (0) value. The Input 2 Port of the Compare is Linked to the Output Port of a Constant Node set (in its Attribute Manager) at the value 10.
Therefore, the Compare Node will output a True momentarily when the animation has reached the Frame no. set at its Input 2 (Frame no. 10), and then return to False for the remainder of the animation.
The three bottom Time, Constant and Compare nodes are essentially mirror images of the top three except that the bottom Constant Node's Output Port is set at 30 and the Output Port of the Compare node is Linked to Input 2 of the flipflop node. Bearing in mind the operation of the Flipflop Node (above), a little thought should make it clear that Flipflop's Output Port (Boolean) will change to True at Frame 10 and stay at True until Frame 30 when it will change back to False.
You can see this in action by running the animation to its end and then when it starts again stop it before Frame 10. (Result and Spy Nodes do not show correct values while the animation is running.) Note that Flipflop's output is at False (0). Now advance the animation frame-by-frame until Frame 10 and you will see Flipflop's Output Port change to True (1) and stay there at frame 11, 12, 13, etc. until Frame 30 is reached when it will change back to False (0).
So what can this do practically? Here, the Output Port of Flipflop is Linked (via a Spy node) to a Light Node. (A node for any object in the Object Manager can be created by simply dragging the name of that object in the Object Manager on to the Xpresso Editor's window, and repositioning it, if necessary, by dragging its title to a convenient place.) The Light Node has an Input Port called Brightness which when provided with a Boolean False causes the light to be off, and when True causes it to be on.
Now run the animation as before and as the Frame number reaches 10 note that the Light's Input Port changes to True (1) and stays at that value until Frame 30, when it changes to False (0). The actual operation of the Light can be seen in the Viewport (preferably in Perspective) where you will see it switching on and off at the set Frame numbers.