Ex : press a button then flag^=1;

Deal All :

Does it has like title can be come true?
How do to?

Thank u.

Show us what you have tried and tell us what doesn't work

Dear Sir :

It just a idea.

I hope it like C,below :
if(button==0) flag=1;
else flag=0;

Thank u.

better if you can read the documentation. You will come up with better idea.

Dear Sir :

Ok,I will try to understand...

Thank u.

That should work, assuming that button is the variable you want to test and you want to set the value of an already declared variable flag

For basic javascript help the w3schools site is good. JavaScript Tutorial

Colin

Dear Sir :

I will read the information from the w3schools.

Thank u.

Dear Sir :

At pic red circle, Why flag no change?

Thank u.


^= is a bitwise XOR assignment
flag = flag XOR 1
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment

Is that really what you are trying to do?
Why?

Dear jbudd :

If I want to control LED is on/off,
Should to do like that...
But flag^=1; (not correct, why?)
Cause Let flag=0; ??? So How can I to initial flag in right place?

Thank u.

Your button can send a number (0 or 1), a boolean (true or false), a string ("ON" or "OFF").
Make it send the datatype that you need to control the LED and get rid of the function node.

Dear jbudd :

But the ui_button just can only true or false!

Thank u.

[quote="jlian168, post:12, topic:47724"]
But the ui_button just can only true or false!
[/quote

Note the "When clicked send:" setting at the bottom of this shot
image

Again, as per your other thread, you need to use context to hold the existing flag state, as @knolleary showed you.

Dear All Sir : Thanks for ur reply...

ok, I see.
And hv a question to I need to ask knolleary...

Thanks All Sir again.

Dear dceejay :

Sorry..., Here again. Still cant be correct! at pic and below :

  1. I press Toggle SW 2 times it still send 1 to debug window.
  2. So my code where is wrong?

Thank u.

You return msg inside the if block - which means the context.set() line at the end does not get called,

Move the context.set line to just before the return msg line.

Dear knolleary :

Oh, I see, Im so so so stupid..haha.

Thank u very much.

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