This is the code from inside a node I have in a subflow
.
When I am editing it it shows an error in line 15:
context.set("counter",max-1);
I'm not seeing the elephant.
Code:
let counter = context.get("counter") || 0;
// Get values from $env variables.
let UP = env.get("up");
let DOWN = env.get("down");
let offline = env.get("offlinemsg");
let max = env.get("max");
//node.warn("Counter is at value " + counter);
//node.status({text: "Counter is at value " + counter});
if (msg.payload == "RESET")
{
// Reset and allow update
context.set("counter",max-1);
}
if (msg.payload == UP)
{
// UP
//node.warn("+1");
if (counter < max)
{
//
// Do things here.
counter = counter + 1;
node.status({text: counter});
context.set("counter",counter);
if (counter == max)
{
msg.payload = offline;
node.status({text: "OFFLINE"});
return msg;
}
// Ok
// Therefore do/send NOTHING
return;
}
} else
if (msg.payload == DOWN)
{
counter = 0;
context.set("counter",counter);
node.status({text: counter});
msg.payload = true;
return msg;
}