Conditions (if statements)

Another interesting possibility is the use of conditions with the “if” statement. With this method you are able to trigger, stop or switch values, settings, and properties. The “if” function always needs three arguments, enclosed in brackets:

if(value1, value2, value3)

The first value is a comparison to specify a certain trigger point, e.g. a particular frame or point in time:

if(f<49, value1, value2)

This means that from the moment the timeline reaches frame 50, “value1” will be switched to “value2”. You can also perform checks with the equality operator “=”:

if(t=5.0, value1, value2)

Instead you can use values from other objects and nodes for comparisons, like this one:

if(Null01.rotation_X < 180, value1, value2)

 

An example:

You want to create a sine-shaped motion with an overlapping random noise, but with frame 75 the attribute’s value should become 0. Such an expression is no problem with the “if” statement:

if(f<75,cos(t*5)+rnd(1),0)

In other words: When the current reaches 75 then switch the function sin(t*5)+rnd(1) to 0.0. Here is an image of the condition above:

 

The condition (f<75,cos(t*5)+rnd(1),0) tells RealFlow to set the value to 0 with frame 75.


Another interesting feature is to switch on rigid body dynamics at a certain moment. Choose the node’s “Dynamics” parameter, open the curve and enter:

if(f<99,1,0)

With frame 100 active rigid body dynamics will be turned on. The notation might appear strange at first glance, but with expressions it is not possible to use strings, so an expression like this is not valid:

if(f<99,”Active rigid body”,”No”)

To overcome this limitation, the list entries from the dynamics panel or other properties are numbered:

  • 0 = No

  • 1 = Active rigid body

  • 2 = Passive rigid body

  • 3 = Soft body

So if you want to A) turn on “Soft body” dynamics at frame 100, or B) switch from “Passive rigid body” to “Soft body” dynamics, the expressions look like these:

A) if(f<99,3,0)

B) if(f<99,3,2)


Conditions are an easy, but powerful means of creating all kinds of switches or triggers for applying functions. The best idea is to play a little bit with this useful feature and explore its possibilities. You will soon discover that you actually will not be able to do without conditions, once you have understood the concept. In particular, dependencies from other nodes’ attributes can create complex, formula-driven animations.