Action-level conditions allow you to control whether or not an action triggers the actions that are connected to it.
The condition is entered via "Set Condition" in the context menu of the action. The dialog that appears has a field in which you can enter the condition. After it was initially entered the condition appears in a text field in the action's slot and can be edited there. Also, the action's icon changes from an arrow to a question mark.
When the action is run the condition is checked by comparing it to the parameters passed into the action. If the condition is _not_ met then processing of the action stops. If it is met then processing continues as it normally would. That means any code in the action is run and, importantly, the other actions connected to the action with the condition are triggered and the received parameter values are passed along to the destination actions. This allows you to build a system of nodes where only those connections are travelled along that start with conditions that have been met.
How the condition is interpreted depends on what was entered. In the simplest case, the condition consists of a single numeric value or a single string. In this case the condition mechanism will compare the first parameter of the action to that value. Consider an action called A(val1, val2), i.e. with parameters named val1 and val2. If a condition is set for this action with just the number 23 then the condition will be met if val1 equals 23.
If several values are entered then the parameters are matched one after the other. In the example above, entering "23, 87" (without the quotation marks) would lead to a condition that is met when val1 equals 23 and val2 equals 87.
Another way to enter a condition is to start with a comparison operator such as >, <, <= or >= and then write a value (e.g. "> 23"). In this case, the first parameter of the action will be compared to the value using the comparison operator. So, the condition for the action A() would only be met if val1 was larger than 23.
These kinds of conditions are generated by the system when it detects that only individual values and comparison operators have been entered. In principle, though, conditions can contain any valid Lua code and, when this is detected, the condition is used exactly as entered. For one thing, this gives you more freedom in relating goal values to parameters. For example, you could enter "val1 > 23 or val2 == 90" (without quotation marks) to create a condition that is met either if val1 is greater than 23 or val2 is equal to 90.
Beyond referencing the parameters you can also run other code as part of the condition. For example, assume you have an action getSeconds() in a module called TimeInfo that calculates a number of seconds and returns that number by using the Lua return statement as its last line (for the sake of this example the reasoning behind TimeInfo.getSeconds() is not important, it is just a stand-in for any action that returns a value that we are interested in). If you need a different action to only trigger its connections when the time has reached a certain value you could enter "TimeInfo.getSeconds() > 30" (without the quotation marks) directly into the condition. Now, when the action is run, the condition evaluation will ignore the passed-in parameters. Rather, it will run TimeInfo.getSeconds() and only consider the condition as met if the value it receives from getSeconds() is greater than 30.
Often the situations in which a condition is not met are just as interesting as those in which it is met. To react to un-met conditions you can set an else-action. To do this, create an action directly under an action with a condition. In the action's popup menu there will be an entry that starts with "Use as Else For" and then shows the preceding action's name. If you select that entry it will make the action an else-action for the preceding action. This means that the action will run if the preceding action's condition is _not_ met.
You can also set a condition for an else-action. If an else-action has a condition then the fact that the condition of its preceding action was not met is not enough to trigger the else-action. Rather, its own condition must be met as well, leading to what is called an elseif construct. Since the else-action now has a condition it too can have a further else-action associated with it. This allows you to build arbitrarily long chains of actions starting from an initial if, continuing over any number of elseifs and ending in a final else which will only be run if none of the preceding conditions have been met.
Create your module
set input into an action to action(value_name)
wire input to action
right click on action
click on "condition"
set the confition into the created field.
set variable corresponds to is equal to.
type number 1 will pass a signal to the output if input is a 1
You will need to type strings with parenthesis:
"car" will trigger the output if input string is car
The same applies to operators >< >= <=
Nested and/or conditions will need the mention of the value_name:
value_name>=5 and value_name<10
A condition can be a complete API call or can get its information from another action and or module.
Example Condition:
TriggerModule.getSeconds()<30
will check if the action "getSeconds" in the module "TriggerModule" will return a value <30
The code in the "getSeconds" action could be (example):
Else
Create a second action with action_name2(value_name2)
right click on action
choose set as else for action
No input field will appear as all other terms of upper condition will end up in the else part of the condition and trigger the output.
Elseif
To create an elseif for the action_name2 you will first need to create the else statement as mentioned above. If you do not do this you will create a new condition that is not connected to the upper condition. Now do a another right click and you can add the condition that will be used as the elseif statement