0
how to make logical functions javascript
Hi,
I don't have a lot of knowledge in javascript and i want to use logical functions, but i don't get it to work.
i used an example of this forum and i want to make this with it:
if: input1=0 and input2=1
than set: output1->0 , output2->0, output3->0
if: input1=1 and input2=1
than set: output1->1 , output2->1, output3->1
here is the script i made, can anyone tell me what i did wrong?
IR.AddListener(IR.EVENT_START,0,function() { //Lsunch a listener of the basis if global tag work. IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value) { IR.Log("Active global: " + name + "\value: " + value); /* Write logics for required processing. */ if ((name == "Global.input1" && value == 0) && (name == "Global.input2" && value == 1)) { IR.Log("Light OFF") IR.SetVariable("Global.output1", 0) IR.SetVariable("Global.output2", 0) IR.SetVariable("Global.output3", 0) }else /* Write logics for required processing. */ if ((name == "Global.input1" && value == 1) && (name == "Global.input2" && value == 1)) { IR.Log("Light ON") IR.SetVariable("Global.output1", 1) IR.SetVariable("Global.output2", 1) IR.SetVariable("Global.output3", 1) } }); //Signature block for required tags IR.SubscribeTagChange("Global.input1"); IR.SubscribeTagChange("Global.input2") IR.SubscribeTagChange("Global.output1") IR.SubscribeTagChange("Global.output2") IR.SubscribeTagChange("Global.output3") });
I used this example from this forum, but is "IR.setGlobalListener" the best option to use?
If someone has a better suggestion please tell !
Thanks,
Marco
Customer support service by UserEcho
Hi Marco
The global listener is fine and what you need.
From what I can see the problem is with
You are asking if the name is input1 AND input2 when the name can only be input1 OR input2
So you may want to try something like this
I haven't tested this, but it should get you going in the right direction I hope :)
thanks for the reply!
I will try this out.