If/Else Node
Overview
The If/Else Node is a control flow node that allows you to choose between two different values based on a condition. It takes in three inputs: a condition, a true value, and a false value. If the condition is truthy, the true value is passed through the output port. If the condition is not truthy, the false value is passed through the output port.
This node can "consume" a Not Ran to continue a graph from that point. This means that if a Not Ran value is passed into the If port, the False value will be passed through instead. If the False value is not connected, then the result will again be Not Ran.
The If/Else node is particularly useful for always ensuring that a graph returns a value, and the outputs of the graph always run, or ensuring that a later node in the graph always receives a value, even if intermediate nodes do not run.
- Inputs
- Outputs
- Editor Settings
Inputs
| Title | Data Type | Description | Default Value | Notes |
|---|---|---|---|---|
| If | any | The condition to evaluate. If truthy, the true value is passed through. | (required) | The input will be coerced into a boolean if it is not a boolean. |
| True | any | The value to pass through if the condition is truthy. | (empty) | The input will be coerced into the same data type as the False input if it is not the same type. |
| False | any | The value to pass through if the condition is not truthy or is not provided. | (empty) | The input will be coerced into the same data type as the True input if it is not the same type. |
Outputs
| Title | Data Type | Description | Notes |
|---|---|---|---|
| Output | any | The value that was passed through based on the condition. Either the true value or false value. |
Editor Settings
This node has no configurable editor settings.
Example 1: Choose between two values based on a condition
- Create a Bool Node. Set the value of the Bool Node to
true. - Create two Text Nodes. Set the text of one node to
Helloand the other toWorld. - Create an If/Else Node. Connect the Bool Node to the
Ifinput of the If/Else Node. Connect the Text Node with the textHelloto theTrueinput of the If/Else Node. Connect the Text Node with the textWorldto theFalseinput of the If/Else Node. - Run the graph. The output of the If/Else Node should be
Hello. - Try changing the value of the Bool Node to
false. Run the graph again. The output of the If/Else Node should now beWorld.

Example 2: Provide a default value for a missing input
- Create an If Node but do not connect anything to its
Ifinput. - Create two Text Nodes. Set the text of one node to
Helloand the other toWorld. - Connect the Hello Text Node to the
Valueinput of the If Node. - Create an If/Else Node. Connect the If Node to the
IfandTrueinputs of the If/Else Node. Connect the Text Node with the textWorldto theFalseinput of the If/Else Node. - Run the graph. The output of the If/Else Node should be
World.

Error Handling
The If/Else node will not throw an error under normal circumstances.
FAQ
Q: What is considered truthy in Rivet?
A: Any value that is considered truthy in JavaScript, plus any non-empty Array, is considered truthy in Rivet. This includes:
true- Any non-zero number
- Any non-empty string
- Any non-empty Array
- Any object
- Any function
All other values are considered falsy, including the string value "false".
Q: What happens if the If input is Not Ran?
A: If the If input is Not Ran, the False value will be passed through instead. If the False value is not connected, then the result will again be Not Ran.
Q: What happens if the True or False inputs are not provided?
A: If the True or False inputs are not provided, they will default to Not Ran.
Q: Can I use the If/Else Node to choose between two different types of values?
A: Yes, you can use the If/Else Node to choose between two different types of values. For example, you can use it to choose between a string and a number based on a condition. However, keep in mind that the output of the If/Else Node will be of the same type as the value that was passed through.