Function tried to send a message of type string

I.m sure this has been asked before but can't find a solution and tried searching for the relevant javascript solution but didn't help. I'm trying to get 2 values out of a function and get "Function tried to send a message of type string"
Function code below.

global.set("pushed", 1);
global.set("override", 0);
var p = global.get("pushed");
p=p.toString();
var o = global.get("override");
o=o.toString();
var msg1=msg.payload;
var msg2=msg.payload
msg1.payload=p;
msg2.payload=o;
return [ msg1 , msg2 ];

1 Like

Change

to

var msg1={};
var msg2={};
1 Like

That worked perfectly. Many thanks. Hope it helps other newbies to JS and Node-Red.

I think you should also carefully read the manual https://nodered.org/docs/user-guide/messages and do some experiments to understand how to deal with msg Object and its properties.

Thank you. I'll bookmarked that page and will give it a go.