(Give me a gun and let me end this stupidity!)
I don't really get what is going on here.
I've got used to the code: (example)
var j = context.get('name') || 0;
Assign j the value of the context 'name', and if there is no value, assign it 0.
Easy.
So, I'm working on a node which needs to store a context of what is going on and then control what happens with messages.
Yeah, this is kind of overkill, but today while writing more stuff, the machine would now and then just lock up.
I had to put in blocks on flows here and there to catch the error.
I then decided to add a MANUAL BLOCK function. But it needs a GUI indication of what is doing on.
So, I needed to nest icons. (Fun there.)
Got that working - after a lot of confusion.
Now I have this block of code:
There are 4 inputs.
2 - data signals of 'on' and 'off'. They are used downstream to switch things on/off.
2 - control inputs to allow/stop the data. They modify the icons sent out. (Nesting icons)
Every time I run it the context which I thought is stored is showing as 1.
The code has old stuff in it as it was originally two nodes which I combined and I left the old code in so I can cut/paste.
I'm leaving it here to ..... "show" (?) you how I think. (Yeah, that's a stretch, but....)
So the code:
var block = context.get('block_context') || 1;
node.warn("Reading context now");
node.warn(block);
if (msg.payload == "STOP")
{
context.set('block_context',1);
node.warn("Blocking active");
node.warn(context.get('block_context'));
msg.payload = []; // not needed now.
} else
if (msg.payload == "GO")
{
context.set('block_context',0);
node.warn("Blocking free");
node.warn(context.get('block_context'));
msg.payload = []; // not needed now.
}
if (msg.payload == "on")
{
//if (block === 0)
if (context.get('block_context')== 0)
{
msg = {payload: '<font color = "lime" i class="fa fa-bullseye fa-2x"></i>'};
node.warn(" ON message received and passed");
return msg;
}
//else if (block == 1)
else if (context.get('block_context')== 1)
{
msg = { payload: '<span class="fa-stack "><font color = "lime" <i class="fa fa-bullseye fa-stack-2x"></i><font color = "black" <i class="fa fa-ban fa-stack-1x"></i><font color = "black" <i class="fa fa-ban fa-rotate-90 fa-stack-1x"></i></span>'}
return msg;
}
} else if (msg.payload == "off")
{
if (block === 0)
{
msg = {payload: '<font color = "red" i class="fa fa-bullseye fa-2x"></i>'};
node.warn(" OFF message received and passed");
return msg;
}
else if (block == 1)
{
msg = { payload: '<span class="fa-stack "><font color = "red" <i class="fa fa-bullseye fa-stack-2x"></i><font color = "black" <i class="fa fa-ban fa-stack-1x"></i><font color = "black" <i class="fa fa-ban fa-rotate-90 fa-stack-1x"></i></span>'}
return msg;
}
}
//return msg;
I send it 'GO' signals and I get the initial 1 which is changed to 0.
Then I press 'GO' again. It shows the "initial" value as 1 - again. But I just set it to 0.
See above.
See picture of flow.