Problem with function node analysing OSC

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:

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

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?

As suggested it may well be in msg.payload.

There’s a great page in the docs (Working with messages : Node-RED) 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

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

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.

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

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?

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