Why does this function not work?

I try to achieve following function:

if (msg.payload=="double_clicked"){
 return [{payload:msg.payload.on=true},

What am I missing? Why I cant set and return an object?

Assignment should be done outside of the object creation.

Also, if msg.payload REALLY DOES == "double_clicked", then it is a string (not an object) so you can't suddenly set msg.payload.on=true anyway!

I assume this is what you want...

if (msg.payload=="double_clicked"){
    msg.payload = {  
        on: true, 
        brightness: 20 
    return msg;

... but its hard to tell. Maybe if you explain what you need

If you are trying to return an array of messages (one to each output) then you want, inside the if
return [{payload: {on: true}}, {payload: {brightness: 20})]
but, as Steve says, we are just guessing.

exactly what I was looking for, thank you!
and yes it is possible to compare the string with if statement.

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