Checking multiple String/numbers in if-statement

Hi. Im struggling since over 1 day with my if statements. i tried anything i know from java but it doesn´t works please help me. Here´s my function node:

var valueFromTrigger1 = parseInt(msg.payload.Trig0); 
var valueFromTrigger2 = parseInt(msg.payload.Trig1); 
var valueFromTrigger3 = parseInt(msg.payload.Trig2); 
var valueFromTrigger4 = parseInt(msg.payload.Trig3); 
var valueFromTrigger5 = parseInt(msg.payload.Trig4); 
var valueFromDatabase1 = parseInt(msg.payload.Wert0);
var valueFromDatabase2 = parseInt(msg.payload.Wert1);
var valueFromDatabase3 = parseInt(msg.payload.Wert2);
var valueFromDatabase4 = parseInt(msg.payload.Wert3);
var valueFromDatabase5 = parseInt(msg.payload.Wert4);
var kindOfTrigger = msg.payload.T.toString();
var valueToSet = msg.payload.TV.toString().toString(16);
var valueToSetInDb = msg.payload.TV;

if(valueFromTrigger1 == valueFromDatabase1 && valueFromTrigger2 == valueFromDatabase2 && valueFromTrigger3 == valueFromDatabase3 && valueFromTrigger4 == valueFromDatabase4 && valueFromTrigger5 == valueFromDatabase5 && kindOfTrigger == "set all adresses"){
    for(i=0;i<=111;i++){
        var currentAdress= i.toString().toString(16);
        var newMsg = msg;
        newMsg.payload =  new Buffer(["0x7c","0x06","0x05","0x01", currentAdress , valueToSet ]); 
       // newMsg.topic = "UPDATE BUS SET WERT= "+"\'"+valueToSetInDb+"\'"+"  WHERE BUSNUMMER= "+"\'"+i+"\'"+"" ;
        node.send(newMsg);
    }
    
}else if(valueFromTrigger1 == valueFromDatabase1 && valueFromTrigger2 == valueFromDatabase2 && valueFromTrigger3 == valueFromDatabase3 && valueFromTrigger4 == valueFromDatabase4 && valueFromTrigger5 == valueFromDatabase5 && kindOfTrigger == "set every even adress"){
    for(i=0;i<=111;i+=2){
        var currentAdress1= i.toString().toString(16);
        var newMsg1 = msg;
        newMsg1.payload=  new Buffer(["0x7c","0x06","0x05","0x01", currentAdress1 , valueToSet ]); 
      //  newMsg1.topic = "UPDATE BUS SET WERT= "+"\'"+valueToSetInDb+"\'"+"  WHERE BUSNUMMER= "+"\'"+i+"\'"+"" ;
        node.send(newMsg1);
    }
    
}else if(valueFromTrigger1 == valueFromDatabase1 && valueFromTrigger2 == valueFromDatabase2 && valueFromTrigger3 == valueFromDatabase3 && valueFromTrigger4 == valueFromDatabase4 && valueFromTrigger5 == valueFromDatabase5 && kindOfTrigger == "set every odd adress"){
    for(i=1;i<=111;i+=2){
        var currentAdress2= i.toString().toString(16);
        var newMsg2 = msg;
        newMsg2.payload=  new Buffer(["0x7c","0x06","0x05","0x01", currentAdress2 , valueToSet ]); 
       // newMsg2.topic = "UPDATE BUS SET WERT= "+"\'"+valueToSetInDb+"\'"+"  WHERE BUSNUMMER= "+"\'"+i+"\'"+"" ;
        node.send(newMsg2);
    }
    
}

only the if-statement is the relevant part

It is unclear what the function node must do.
What is the input and what is the expected output ?

the inputs are numbers as strings except kindOfTrigger. If i dont convert them to ints the statement is always true and only the kindOfTrigger-part decides which body will be executed. Converted to Int none of the bodys is executed.
Input:


expected output is the msg.payload

my only problem is that the if statement doesnt works

i got it. i have to write it like this grafik .
Thanks for answering

1 Like

I just saw it also.

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