An archive of as of Saturday January 26, 2019.

Strange Problem with if statement


I have the following code:

local tankList = {};
tankList = nv.AnodizingTanks;

foreach (tank in tankList){
    local cf = tank.TempFC;
    print(tank.TempFC == "C");
    if(tank.TempFC == "C") {
        tank.Temp = probeList[tank.Probe].readT();
        tank.Temp = CtoF(probeList[tank.Probe].readT(), false);

On the if(tank.TempFC == "C") it always goes to the true statement: tank.Temp = probeList[tank.Probe].readT();

Even though the local cf shows a F and the print(tank.TempFC == "C"); says false it still goes to true.

I have no idea what I'm doing wrong. I've done if else statements thousands of times.

This is one of 6 in the nv.AnodizingTanks:

Anodizing = {
Id = 0,
Name = "Anodizing",
ShortName = "Anodizing",
Temp = 0,
Probe = 0,
MinTemp = 65,
MaxTemp = 72,
TempFC = "F",
Alarm = 1,
Active = 1




I just tried your code on my Esquilo and it took the else (false) path on the if. If you are stepping through the code in the debugger, then be careful because occasionally the Squirrel compiler will have the lines off by one. Try putting a print inside both if clauses to verify the path.


I'm feeling pretty stupid right now frowning I had two of those loops and I only changed one of them. The one that keeps updating the temp in my main loop wasn't changed.

So I made a function so now have only one piece of that code in there.

Thanks a lot Scott for your help.