Conditions

Conditions are an essential feature in the Berkeley Studio. They give you control over what will happen at what point. At the very basic level, they check what a user answered and use that to determine what node to go to (see Getting started with conditions).

However, you can do a lot more with conditions. The most important aspect of conditions is the use of operators. Consider “I want the user to go to node taxes when he has more than €10.000,- on his account”. To do so, you can ask the user a question about his or her account balance. Now all you have to do is add the condition.

In this case, we need the greater-than operator (`>`). This operator checks whether or not everything on the left of it is larger than what’s on the right. For example, `5 > 3` reads as “five is larger than three”, which is of course always true. However, when we use `account_balance > 10000`, it depends on the account balance!

In the Berkeley Studio, you can use this kind of logic to send users through a specific path. In the example above, whenever the user enters €500,- as their bank account, `account_balance > 10000` will not be true (500 is not larger than 10.000) and the user will not be send to taxes.

Conditions can also be used in formulas or text fragments. We will discuss several examples below.

Adding a condition for a connection

In order to make the taxes model described above, we need our own condition. To do so, make a model with three nodes: the start node, a node taxes and a node House. The latter two both have to be connected to the start node. It is also good to add some text to them, so you’ll notice when you arrive at them.

Now, in order to guide the user to the right node, double-click the connection from start to taxes. There are several ways of entering a condition. The first is to simply type your condition in the condition field. However, for less experienced users there is a help screen. You can access it by selecting the button left of the field, as shown below.

You can now enter the condition in the screen shown below. The button for the Finder is highlighted.

On the left of the equals-sign (`=`), enter `account_balance` and on the right enter `10000`. Furthermore, make sure to change the equals sign (`=`) to a greater-than operator `>`. You can use the Finder to look up the account balance variable. You should end up with the following screen:

Adding a condition for a formula

Formulas can be made conditional as well. We will use the same model as used with the previous example. However, we will add a formula in the taxes node. This formula will calculate the amount of taxes the user has to pay. It will be dependant on the account balance.

To do so, add a formula called tax to the node taxes. When the user has more than €20.000,- on his account, he or she will have to pay 30% as tax. You can model this with the following formula: `start.account_balance * 0.3`, as can be seen in the picture below.

Now you can add the condition. Again, you can do this in multiple ways. The most convenient is by using the Finder to select the right variable and change the equals sign (`=`). You should get a screen as shown below.

Adding a condition for a text fragment

Adding a condition to a text fragment works exactly the same as for a formula or connection. It is especially useful if you are interested in document assembly. For more information on conditions in text fragments, see conditional text fragments.

Using multiple conditions with AND and OR

Sometimes you will need more complicated logic in your model. For example, only people who have more than €10.000,- on their account and have no debts, or people own both a car and a house. In those cases, you can make use of the `AND` and `OR` operators. `AND` and `OR` can combine multiple conditions. Below is an example of an `AND` condition:

In this example, only users who have a car and have more than €10.000,- on their account will go to the node taxes. Having a car but not more than €10.000,- will not work.

Important! You have to put parentheses around each condition!

The `OR` operator works slightly different. It will be true if either one of the conditions is true. In the example above, replacing `AND` by `OR` will send anyone with either a car or €10.000,- to the tax node.