dimanche 31 janvier 2016

Greater than condition is met even though it should not?

In my code I am trying to make a chat delay system and all the variables are correct but the greater than condition is being met even though it should not. I added a console.log to check the numbers

    function sendChat(str) {
    if (wsIsOpen() && (str.length < 200) && (str.length > 0) &&
    (Math.round(new Date() / 1000)) > (lastchat + delay2) ) {
        for (var i = 0; i < arrayLength; i++) {
                if (str.toLowerCase().indexOf(badWords[i]) < 0){
                }
                else{
                    swear = true;
                    console.log(badWords[i])
                }
            }
        }
        if (swear == false) {
            var msg = prepareData(2 + 2 * str.length);
            var offset = 0;
            msg.setUint8(offset++, 99);
            msg.setUint8(offset++, 0); // flags (0 for now)
            for (var i = 0; i < str.length; ++i) {
                msg.setUint16(offset, str.charCodeAt(i), true);
                offset += 2;
            swear = false;
        }
        var a2 = msg;
        wsSend(msg);
        //console.log(msg);
        lastchat = Math.round(new Date() / 1000);
        console.log(Math.round(new Date() / 1000) + ">" + (lastchat + delay2))
    }
}

In console it says: main_out.js:838 1454261443>1454261445

Aucun commentaire:

Enregistrer un commentaire