Hi There
I'm quite new and have a problem with using a variable in defining the msgX = Number... for Output in a function node. I want to replace msg1, msg2, msg3.... with msgt, msg't', {msg;t} or so to use loop counter for topic and message number. Example in the line with "<-------" in code below
But I don't know how to write the variable as addendum for msg number....
if (msg.topic == "init"){
msg1 = {payload:0}
msg2 = {payload:0}
msg3 = {payload:0}
x = 0
}
if (msg.payload == 1 ){x = x + 1}
if (msg.payload === 0 && x > 0 ){x = x - 1}
for( t = 1; t < 2; t++){
if (msg.topic == t && msg.payload == 1 && x < 3){msg{t} = {payload:1}} // <-------
if (msg.topic == t && msg.payload == 1 && x > 2){msg1 = {payload:0}}
if (msg.topic == t && msg.payload === 0 ) {msg1 = {payload:0}}
if (msg.topic == 2 && msg.payload == 1 && x < 3){msg2 = {payload:1}}
if (msg.topic == 2 && msg.payload == 1 && x > 2){msg2 = {payload:0}}
if (msg.topic == 2 && msg.payload === 0 ) {msg2 = {payload:0}}
if (msg.topic == 3 && msg.payload == 1 && x < 3){msg3 = {payload:1}}
if (msg.topic == 3 && msg.payload == 1 && x > 2){msg3 = {payload:0}}
if (msg.topic == 3 && msg.payload === 0 ) {msg3 = {payload:0}}
}
msg4 = {payload:x}
return [msg1, msg2, msg3, msg4];
Thanks!!