Start a new topic

how can I conditionally route an output depending on the value?

this isn't dynamic. 


given a single output from a component you can choose where it gets routed to by having one merge gate for each route. 


connect the output of source to the input x0 and x1 of each merge gate. x0 is the data you want to pass through if the condition is met. x1 is the condition. In the merge gate's condition field use x1== condition and timeOf('x0').


Change the condition in each merge gate depending on where you want it to route to. 


you can use any input source for the condition, not just itself. e.g., a check box prompt outputs true or false and can easily serve as the switch. 

1 Comment

Hi Tom, I made a system for doing this, but I'm not sure how well it'd fit your scenario. I made a 'switch' component that takes an array of strings, one for each route output, then those are dynamically generated. There's a payload input, which will be what's passed through the proper route, depending on the `switchState` input, which should match one of the route names.


So an example would be that we're sending 'age' through, which is an integer, and if it's under 18 I want their age to go through 'minor', if they're 18 or over, I want to go through 'adult'. So I'd set 'possibleValues' to ["minor", "adult"] and I'd have my outputs generated. Then I'd wire 'age' to payload, and I'd also wire 'age' through a data merge gate that does a conditonal check:


 

x0 < 18 ? "minor" : "adult"

 


Then I'd wire the output of that data merge gate to the switch component's "switchState" input. Then it'd route age out the appropriate path.


Let me know if this sounds like it might be helpful and I'll get that component to you and you can adjust it as needed.


Login to post a comment