# Problem with function node analysing OSC

**URL:** <https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690>\
**Category:** General\
**Created:** [27 October 2022 19:29 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690 "2022-10-27T19:29:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhoepffner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jhoepffner/32/69679_2.png) [@jhoepffner](https://discourse.nodered.org/u/jhoepffner)\
**Post date:** [27 October 2022 19:29 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/1 "2022-10-27T19:29:24Z")

</div>

Hello,  
I am a newby with Node-Red.  
I search to implement a simple function.  
Info is coming from TouchDesigner through OSC (udp) as:  
{"address":"/videoShow","args":0}  
I want to change property of group with args (two values, 0 and 1)  
I wrote this function:

```auto
var newMsg;
if (msg.args === 1) {
    newMsg = { "group": { "show": ["Demo_video"] } };
} else {
    newMsg = { "group": { "hide": ["Demo_video"] } };
}
msg.payload = newMsg;
return msg;

```

It always send the second value (hide), never recognising 1.  
What I had done wrong?

I practice a lot Python but I am not fluent with JavaScript.  
Thank you in advance for your help,  
Jacques

---

<div class="post-metadata">

**Author:** ![FiloCara](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/filocara/32/27473_2.png) [@FiloCara](https://discourse.nodered.org/u/FiloCara)\
**Post date:** [27 October 2022 19:59 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/2 "2022-10-27T19:59:55Z")

</div>

Hello,

I see two possible causes: `msg.args` is not of type _Number_ or `msg.args` does not exist.

In the first case, you can replace the _three equals_ (===) operator with the _double equals_ (==) to do type conversion of the operands before comparison.

If the data type is correct, are you sure you are not confusing `msg.args` with `msg.payload.args`?

---

<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:** [27 October 2022 20:06 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/3 "2022-10-27T20:06:02Z")

</div>

As suggested it may well be in msg.payload.

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![jhoepffner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jhoepffner/32/69679_2.png) [@jhoepffner](https://discourse.nodered.org/u/jhoepffner)\
**Post date:** [27 October 2022 20:31 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/4 "2022-10-27T20:31:48Z")

</div>

Thank you for your quick and kind answers.  
I tried msg.payload, msg.payload.args, msg.args with == and === and nothing works ☹  
Finaly I opted for the easy visual programing solution : switch (on msg.payload) and 2 x change (on Set msg.payload) 🙂  
Its working,  
Have a nice evening (here in Paris),  
Jacques

---

<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:** [27 October 2022 21:10 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/5 "2022-10-27T21:10:12Z")

</div>

I am sure you would like to know why it doesn't work (for next time). Feed the incoming message into a debug node and show us what you see.

---

<div class="post-metadata">

**Author:** ![jhoepffner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jhoepffner/32/69679_2.png) [@jhoepffner](https://discourse.nodered.org/u/jhoepffner)\
**Post date:** [27 October 2022 21:19 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/6 "2022-10-27T21:19:29Z")

</div>

Sure, I would like to resolve the problem!  
Here is what I obtain with msg.payload.args  
27/10/2022 23:13:15[node: debug 2](http://192.168.1.16:1880/#)bundle : msg.payload : Object  
object  
group: object  
hide: array[1]  
0: "Demo\_video"

---

<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:** [28 October 2022 06:31 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/7 "2022-10-28T06:31:33Z")

</div>

There is no `args` value there, so according to your first post args is not 1 so the answer should be `hide`. Is that not what you wanted?

---

<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:** [27 December 2022 06:32 UTC](https://discourse.nodered.org/t/problem-with-function-node-analysing-osc/69690/8 "2022-12-27T06:32:14Z")

</div>

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