# A change in parodyme for flow construction and the \`GATE\` node

**URL:** <https://discourse.nodered.org/t/a-change-in-parodyme-for-flow-construction-and-the-gate-node/19892>\
**Category:** General\
**Created:** [4 January 2020 03:40 UTC](https://discourse.nodered.org/t/a-change-in-parodyme-for-flow-construction-and-the-gate-node/19892 "2020-01-04T03:40:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 January 2020 03:40 UTC](https://discourse.nodered.org/t/a-change-in-parodyme-for-flow-construction-and-the-gate-node/19892/1 "2020-01-04T03:40:12Z")

</div>

I admit I am still learning some of the existing nodes.

When I got into NR a bit further I was wanting a way to control if a message could pass a point.

By default there is no obvious way of doing this with the supplied nodes.

The way around it for me was this way:

```auto
[{"id":"de6e9992.645088","type":"link in","z":"8c64c96f.09f13","name":"TRAIN","links":["8fd2d7ca.72146"],"x":810,"y":2260,"wires":[["590e4a25.90892c","81d505d2.aa7da8"]],"l":true},{"id":"590e4a25.90892c","type":"function","z":"8c64c96f.09f13","name":"Train detect","func":"let m = flow.get('MODE');\nif (m == \"HOLD\")\n{\n // HOLD\n flow.set('TRAIN','HELD');\n// msg.payload = \"STOP\";\n// return msg;\n return; // Don't return anything.\n // Though I may need to send\n // something as a \"signal\" of\n // a new message.\n}\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":2260,"wires":[["79823e18.d22d68"]]},{"id":"81d505d2.aa7da8","type":"change","z":"8c64c96f.09f13","name":"Get MODE","rules":[{"t":"set","p":"payload","pt":"msg","to":"MODE","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":2190,"wires":[["1ba6b9d7.19f76e"]]},{"id":"1ba6b9d7.19f76e","type":"switch","z":"8c64c96f.09f13","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"HOLD","vt":"str"},{"t":"eq","v":"RELEASE","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1140,"y":2190,"wires":[["916777f.3131688"],["817bae21.99f678"]]},{"id":"817bae21.99f678","type":"change","z":"8c64c96f.09f13","name":"Allow","rules":[{"t":"set","p":"payload","pt":"msg","to":"GO","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":2210,"wires":[["79823e18.d22d68"]]},{"id":"79823e18.d22d68","type":"gate","z":"8c64c96f.09f13","name":"","controlTopic":"CONTROL","defaultState":"open","openCmd":"GO","closeCmd":"STOP","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1470,"y":2260,"wires":[[]]},{"id":"916777f.3131688","type":"change","z":"8c64c96f.09f13","name":"Stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":2160,"wires":[["79823e18.d22d68"]]},{"id":"924ab50e.4d2258","type":"comment","z":"8c64c96f.09f13","name":"Allow trains to pass (or stop them)","info":"","x":1080,"y":2120,"wires":[]}]

```

Which looks like this:  
 ![Screenshot from 2020-01-04 14-31-37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/05bfb70059f0d49599155029e19a1c517f8415a4.png)

And this is better than the original way I did it by having a separate message to control the flow.  
The example uses a `flow` variable to do it.

Walk through:  
A message arrives a the `TRAIN` input node.  
Going up, it gets the `flow.MODE` and then splits if it is `ON` or `OFF`.  
That then makes two messages which are sent to the `gate` node to allow/block the message.

Though it works, I only now realised an EASIER way of doing just that.  
Granted it is a given that you are reading a context (right term?) variable rather than a message.

But all that could be replaced with this:

```auto
[{"id":"de6e9992.645088","type":"link in","z":"8c64c96f.09f13","name":"TRAIN","links":["8fd2d7ca.72146"],"x":950,"y":2260,"wires":[["1ba6b9d7.19f76e"]],"l":true},{"id":"1ba6b9d7.19f76e","type":"switch","z":"8c64c96f.09f13","name":"","property":"MODE","propertyType":"flow","rules":[{"t":"eq","v":"ALLOW","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1110,"y":2260,"wires":[["79823e18.d22d68"]]},{"id":"79823e18.d22d68","type":"gate","z":"8c64c96f.09f13","name":"","controlTopic":"CONTROL","defaultState":"open","openCmd":"GO","closeCmd":"STOP","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1300,"y":2260,"wires":[[]]},{"id":"924ab50e.4d2258","type":"comment","z":"8c64c96f.09f13","name":"Allow trains to pass (or stop them)","info":"","x":1130,"y":2190,"wires":[]}]

```

Or:  
Graphically

![Screenshot from 2020-01-04 14-37-32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/779a87da20c642e96a137ba9eb67a33a35b9f320.png)

So much easier and compact.

Basically it works like so:

As before, message arrives at `TRAIN` node.

The `switch` node:  
check if `flow.MODE == "Allow"` (for example)  
If it does match, it passes the message.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [4 January 2020 06:40 UTC](https://discourse.nodered.org/t/a-change-in-parodyme-for-flow-construction-and-the-gate-node/19892/2 "2020-01-04T06:40:11Z")

</div>

To give you more food for thought: do you need the gate node ?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 January 2020 21:33 UTC](https://discourse.nodered.org/t/a-change-in-parodyme-for-flow-construction-and-the-gate-node/19892/3 "2020-01-04T21:33:18Z")

</div>

Ah!

I goofed.

In the original flow I posted, it was to _switch_ (control) the state of the `gate` node that then either stops or allows things to go through it.

I didn't include the part of the flow which was controlled. I only went as far as the `gate` node.

Really the `switch` node in the last flow is all that is needed in the _bigger_ flow to switch/control the flow of messages.

I guess I am still making my mistakes of posting too quickly and not thinking of the bigger picture.

(One step forward, two back.) Oh well.

Thanks for the heads up though.
