Conditional Execution

There's currently two basic ways to do If/Else style "Conditional Execution" in Pictorus.

The first is using the Switch Block, which allow you to pass different signals through the block based on a Condition (the first input to the block).

You can add many conditions to a Switch Block, and you can chain them together to form complex logic. Here's an example where we command a heater ON (100%) or OFF (0%) based on whether the simulated room temperature is below 60 degrees:

House temp example

One drawback to the Switch Block approach is that is doesn't prevent the execution of any sequence of blocks. All possible outputs get computed, but only one gets passed through.

If you really only want to execute a sequence of code if some condition is True, you need to use Conditionally Executed Components. To do this, simply create a Component, go to its settings, and toggle Conditionally Executed:

Conditional Component example

By doing this, you'll notice a special inport appears at the top-left of the Component. This is the conditional trigger. The logic contained within the Component will only be executed when the signal attached to this port is True.

Here's an example where we use conditional execution to periodically sample its input:

Conditional Component example

Conditional execution can be very useful, both as a regulating mechanism (i.e. enforcing different update rates for different parts of the app), as well as for preventing execution of dangerous code (divide by zero, etc).