# \[Feature Request\]Help prevent crossing wires from Switch node

**URL:** <https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233>\
**Category:** General\
**Created:** [15 February 2023 12:02 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233 "2023-02-15T12:02:53Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 February 2023 09:35 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/21 "2023-02-16T09:35:46Z")

</div>

I'd be happy if the node worked like that but it doesn't at the moment

> [@Colin](#):
>
> It seems there is a bug in `otherwise`

I wouldn't call it a bug - it's just not been programmed to behave that way

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [16 February 2023 09:40 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/22 "2023-02-16T09:40:03Z")

</div>

I'm confused - it works for me.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abc359bc823c7e9739496aff81e3a27465ea5689.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48d8b391773313e0b360404ac1dc2015306a6034.png)

If I click on "ccc" it goes to "debug 60", which is the otherwise.

```auto
[{"id":"d618726bede89c3e","type":"inject","z":"3859418dcecf022c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"aaa","payloadType":"str","x":330,"y":80,"wires":[["1ed873439f089a73"]]},{"id":"1ed873439f089a73","type":"switch","z":"3859418dcecf022c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"else"},{"t":"cont","v":"aaa","vt":"str"},{"t":"cont","v":"bbb","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":530,"y":120,"wires":[["8938789f521e0e3f"],["d59ddd2155f68c8f"],["ab5f960a912e47ae"]]},{"id":"d59ddd2155f68c8f","type":"debug","z":"3859418dcecf022c","name":"debug 58","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":80,"wires":[]},{"id":"ab5f960a912e47ae","type":"debug","z":"3859418dcecf022c","name":"debug 59","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":120,"wires":[]},{"id":"8938789f521e0e3f","type":"debug","z":"3859418dcecf022c","name":"debug 60","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":160,"wires":[]},{"id":"c7276c42f343c2fd","type":"inject","z":"3859418dcecf022c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bbb","payloadType":"str","x":330,"y":120,"wires":[["1ed873439f089a73"]]},{"id":"fa3bd97aa1605eb6","type":"inject","z":"3859418dcecf022c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ccc","payloadType":"str","x":330,"y":160,"wires":[["1ed873439f089a73"]]}]

```

And "aaa" and "bbb" go to the expected outputs. Maybe it's the gin.

Running on 3.0.0. Could I be so bold as to suggest it's because I added the "otherwise" last and then dragged it first? That would be bad.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 February 2023 10:00 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/23 "2023-02-16T10:00:43Z")

</div>

> [@michaelblight](#):
>
> Maybe it's the gin

I think so 🙂

When you say

> [@michaelblight](#):
>
> And "aaa" and "bbb" go to the expected outputs.

Define "expected"  
I "want" aaa only to go to output 2 (debug 58)  
Not outputs 2 AND 1 🙂

And i think crossing the wires in your example doesn't lend clarity 🙂  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a8fab168ebf027e72a717e0676a5c9070cf979b7.png)

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [16 February 2023 10:13 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/24 "2023-02-16T10:13:52Z")

</div>

The impact of the gin is I tried changing from "stopping after first match" to "checking all rules". That doesn't work, and that's what I posted. If you change to "stopping after first match" it works for me. Time for another gin.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 February 2023 10:16 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/25 "2023-02-16T10:16:37Z")

</div>

> [@michaelblight](#):
>
> Time for another gin.

STOP!!! 🙂  
When I change to stopping after 1st match, then all that happens is that all inputs get routed to output 1 (debug 60)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/230eaa86b80332a9b797b162e29b07e99acb2a4b.png)

If this really doesn't happen to you then what is the number of the multiverse your living in so I can move there 🙂

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [16 February 2023 10:26 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/26 "2023-02-16T10:26:16Z")

</div>

Yeah ok. Time to stop the gin. It's nighttime here, so it's all above board. Except for my logic of course.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 February 2023 10:35 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/27 "2023-02-16T10:35:50Z")

</div>

> [@cymplecy](#):
>
> I wouldn't call it a bug - it's just not been programmed to behave that way

Well, if I request `Otherwise` then to me that means `if it doesn't match anything else`.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 February 2023 10:43 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/28 "2023-02-16T10:43:26Z")

</div>

Well yes but it requires looking ahead, down the list, to see if would be true

Software doesn't normally behave that way 🙂

Letting it work if it was put at the top would be a great solution to the crossed wires issue but I totally understand why it doesn't at the moment

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 February 2023 15:36 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/29 "2023-02-16T15:36:23Z")

</div>

you are correct - the otherwise is just the catchall bucket at the end of the list.. just like you can't put the else clause first in an if then else statement.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 February 2023 15:51 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/30 "2023-02-16T15:51:51Z")

</div>

Well you can parse the syntax tree in any manner you wish - it's just that no text languages do 🙂  
But nothing intrinsically wrong with saying

```auto
If all else fails {
  DoThis
} else if (Sky ==== blue) {
  GoForPicnic
} else if (Sky ==== grey) {
  ReadABook
}

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 February 2023 16:04 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/31 "2023-02-16T16:04:46Z")

</div>

Arguably, if Otherwise must always go at the end of the list then one should not be able to put it elsewhere.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 February 2023 16:42 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/32 "2023-02-16T16:42:10Z")

</div>

Not even arguably, arguably 🙂

It would be really nice if it pinned itself to the last entry.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 February 2023 17:08 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/33 "2023-02-16T17:08:06Z")

</div>

the ability to re-order was added well after the original, so yes maybe. The original idea was to try to make confg panels "readable" like a sentence - eg the udp input node - Listen for udp messages on port abc using ipv4 and output a string... over time that was untenable and has mostly been dropped, but that's where "otherwise" came from (and why it should be last).

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 February 2023 17:15 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/34 "2023-02-16T17:15:16Z")

</div>

> [@TotallyInformation](#):
>
> It would be really nice if it pinned itself to the last entry.

em- no it wouldn't - it would be nice it it worked at the top as well as the bottom

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 February 2023 18:22 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/35 "2023-02-16T18:22:47Z")

</div>

If it was at the top I think the label would need to change ( eg as you suggested - if all else fails) but yes you will need to handle the out of order execution issues. Somewhat overkill to fix a wire crossing imho but the PR will be interesting 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 February 2023 07:49 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/36 "2023-02-19T07:49:15Z")

</div>

I'm making progress on the PR 🙂

Don't anyone help me - I'm having "fun" trying to do it 🙂

In the meantime, over in Snap!, we now have an "If All Else Fails" construct 🙂

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b8cba978b7cb5e1c4df2570d91e55eae3df5d3b3.png)

[https://snap.berkeley.edu/snap/snap.html#present:Username=cymplecy&ProjectName=ifAllElseFails&editMode](https://snap.berkeley.edu/snap/snap.html#present:Username=cymplecy&ProjectName=ifAllElseFails&editMode)

The revolution has started 🙂

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 February 2023 09:04 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/37 "2023-02-19T09:04:59Z")

</div>

As written that really doesn’t parse in my brain but then again I don’t use scratch either. :-). Have fun

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 February 2023 09:41 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/38 "2023-02-19T09:41:04Z")

</div>

I've made them look more standard for you 🙂

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/babb37518a26e7d8b5f472cb53e20f72c9c9e18f.png)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 February 2023 14:41 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/39 "2023-02-19T14:41:41Z")

</div>

OK - proof of concept 🙂  
This is in a separate dev instance on my Windows machine with modified switch node with some node.warn debugging to show what's happening

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e8f4030ea638bdd556950d303211a810d33cc0f.png)

So, if you click on a

- Rule 0 is checked - could end up being true so we add "pending" to the onward array instead of msg that it normally would be
- Rule 1 is checked - it's true so msg is added to the onward array as per normal
- Rule 2 is checked - it's false so null is added to the onward array as per normal
- Then, all the array items, starting at index 1, are checked for != null and since one is true, then onward[0] is changed from "pending" to null

If b is pressed, it's processed the same as a but output goes to debug 3 of course.

If c is pressed then we get

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d3ac02a18b8ae60bd083c209a476b3771beeb7a.png)

- Rule 0 is checked - could end up being true so we add "pending" to the onward array instead of msg that it normally would be
- Rule 1 is checked - it's false so null is added to the onward array as per normal
- Rule 2 is checked - it's false so null is added to the onward array as per normal
- Then, all the array items, starting at index 1, are checked for != null and since all are null then onward[0] is restored from "pending" back to msg

If the switch is arranged with otherwise as the last rule, then output goes to debug 3 as normal without the onward array being manipulated at all

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/006adc53be970dc63744c4d6a6a488465844482e.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 February 2023 17:35 UTC](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233/40 "2023-02-19T17:35:21Z")

</div>

looks like good progress...  
Just checking - as we do allow checking all rules... what would be the consequence of putting the otherwise in position 2 ? Currently as it's expected to be the end of the sequence it would get evaluated compared to previous rules and output appropriately... and then proceed to the next rules (3). I suspect now it would do the opposite and be tested compared to the later rules.

[Previous page](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233.md?page=1)

[Next page](https://discourse.nodered.org/t/feature-request-help-prevent-crossing-wires-from-switch-node/75233.md?page=3)
