# Flow process help

**URL:** https://discourse.nodered.org/t/flow-process-help/88823
**Category:** General
**Created:** [20 June 2024 19:37 UTC](https://discourse.nodered.org/t/flow-process-help/88823 "2024-06-20T19:37:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Morsey](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/morsey/32/92088_2.png) [@Morsey](https://discourse.nodered.org/u/Morsey)
#### Post date: [20 June 2024 19:37 UTC](https://discourse.nodered.org/t/flow-process-help/88823/1 "2024-06-20T19:37:24Z")

</div>

I am fairly new to node-red, but not to coding.

I am hoping for a bit of guidance to flow layout. I am happy with how to use node-red, the different nodes etc. What I am missing is experience with algorithms for node-red.

I have two devices that communicate with an MQTT server.

The flow needs to:

1. Listen out for a message from an MQTT server topic.
2. check the message content (an integer [1-100]) against a list of numbers and strings ([[0,"a"], [4,"b"], [3,"re"], [6."we"]])
3. if the message matches the current position in the array, send an MQTT message to the second device and progress the place in the array
4. continue until the array has been fully traversed.

The part I am having issues with are holding the "state" of the process. Is using context variables and pretending this is normal code the way forward? or is there a "node-red" way of doing this?

Thanks for any suggestions

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [20 June 2024 20:13 UTC](https://discourse.nodered.org/t/flow-process-help/88823/2 "2024-06-20T20:13:41Z")

</div>

Hello @Morsey and welcome to the forum.

> [@Morsey](#):
>
> The flow needs to:

1. Listen out for a message from an MQTT server topic.  
An mqtt-in node does this.

2. check the message content (an integer [1-100]) against a list of numbers and strings ([[0,"a"], [4,"b"], [3,"re"], [6."we"]])  
The message content is an integer? So what does `[6."we"]` mean?

3. if the message matches the current position in the array, send an MQTT message to the second device and progress the place in the array  
What does "message matches the current position in the array" mean?  
What does "progress the place in the array" mean?

4. continue until the array has been fully traversed.  
Are you saying that the message, an integer, might somehow "match" both `[3, "re"]` and `[6."we"]`?

Maybe you can show us a real example of an incoming message and this occult array of arrays. What output do you expect to get?

> [@Morsey](#):
>
> or is there a "node-red" way of doing this?

There probably is, yes.  
It's generally a mistake to think in terms of variables and procedural code when moving to Node-red.  
If you can explain more clearly what the requirement is, we might be able to suggest a Node-red way to achieve it.

---

<div class="post-metadata">

### Author: ![Morsey](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/morsey/32/92088_2.png) [@Morsey](https://discourse.nodered.org/u/Morsey)
#### Post date: [20 June 2024 21:31 UTC](https://discourse.nodered.org/t/flow-process-help/88823/3 "2024-06-20T21:31:55Z")

</div>

Thanks do the advice, It is an escape room prop.

Device one:

Essentially a sensor. It sends an MQTT message with a number. The number represents a location on a map.

Device two:

Receives an MQTT message telling it what to show. The message it shows is to tell the user where to go next on the map.

Node red’s job:

Receive message from sensor via MQTT  
Check if it is the first step in a defined map “path”. If so send a message to device two with next step message. (North, South,  
East, West)  
Repeat for each step in the path  
If the next location sent from the map is wrong, redo from start

Is that clearer?

---

<div class="post-metadata">

### Author: ![Morsey](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/morsey/32/92088_2.png) [@Morsey](https://discourse.nodered.org/u/Morsey)
#### Post date: [20 June 2024 21:39 UTC](https://discourse.nodered.org/t/flow-process-help/88823/4 "2024-06-20T21:39:10Z")

</div>

Sorry, just noticed your inline replies.

The messages are all written by me. So message from device one is current a json containing one bit of info:

{location:1}

The array is a bit I am unsure of, it needs to be definable, and changeable. In essence is a list of location number (1,4,2,3,…) but each location has a paired “where to go next” location string “north”, “east” etc.

As long as the location sequence is followed then the location string is sent onwards. Currently just a json:

{direction: “north”}

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [20 June 2024 21:54 UTC](https://discourse.nodered.org/t/flow-process-help/88823/5 "2024-06-20T21:54:43Z")

</div>

> [@Morsey](#):
>
> escape room

This might be if interest:

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a9d4870ee9838c441680e87ebf7dfb6c0633a34f.jpeg "Node-REDscape : 100% Free, Open-Source Escape Room Control Software") ](https://www.youtube.com/watch?v=f9yYDxqK_2E)

> **[GitHub - playfultechnology/node-redscape: Node-REDscape is a set of nodes,...](https://github.com/playfultechnology/node-redscape)**
>
> Node-REDscape is a set of nodes, flows, and templates for monitoring and controlling escape room puzzle props using Node-RED - playfultechnology/node-redscape

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 September 2024 21:55 UTC](https://discourse.nodered.org/t/flow-process-help/88823/6 "2024-09-18T21:55:11Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
