# Help with flow selection order gives wrong item

**URL:** https://discourse.nodered.org/t/help-with-flow-selection-order-gives-wrong-item/89527
**Category:** General
**Created:** [15 July 2024 18:44 UTC](https://discourse.nodered.org/t/help-with-flow-selection-order-gives-wrong-item/89527 "2024-07-15T18:44:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kroonp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kroonp/32/68249_2.png) [@kroonp](https://discourse.nodered.org/u/kroonp)
#### Post date: [15 July 2024 18:44 UTC](https://discourse.nodered.org/t/help-with-flow-selection-order-gives-wrong-item/89527/1 "2024-07-15T18:44:21Z")

</div>

Please advise what I am doing wrong?  
In the accompanying flow, the intention is that a scene is started depending on the lux value. If the lux value is between 30-300, wk\_schemer should be selected. However, wk\_avond is selected first and only wk\_schemer at the next trigger.

```auto
// Initialize messages to null
var msg1 = null;
var msg2 = null;
var msg3 = null;
var msg4 = null;

// Initialize context variables if not already defined
context.lux = context.lux || 0;

if (msg.topic == 'lux') {
    context.lux = msg.payload; // Store the payload in context.lux
}
var L = context.lux;

// Determine the setup value based on the lux value
if (L >= 600) {
    msg1 = { payload: { entity_id: "wk_uit" } };
} else if (L >= 300) {
    msg2 = { payload: { entity_id: "wk_dag" } };
} else if (L >= 30) {
    msg3 = { payload: { entity_id: "wk_schemer" } };
} else if (L >= 0 ) {
    msg4 = { payload: { entity_id: "wk_avond" } };
}

// Return the output messages
return [msg1, msg2, msg3, msg4];

```

---

<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: [15 July 2024 19:17 UTC](https://discourse.nodered.org/t/help-with-flow-selection-order-gives-wrong-item/89527/2 "2024-07-15T19:17:38Z")

</div>

Firstly, you need to use `context.get` and `context.set` to get/set context values. Although what you've done might currently work with memory based context, there is no guarantee that it will work in the future. And moving to another context library will also likely fail.

Then I would imagine that msg.payload does not actually contain a number. Probably contains a string number instead which means that your L value is 0.

---

<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: [13 October 2024 19:18 UTC](https://discourse.nodered.org/t/help-with-flow-selection-order-gives-wrong-item/89527/3 "2024-10-13T19:18:28Z")

</div>

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