Tell me I'm not crazy

Tereza Snyder tereza at
Mon Sep 19 16:30:51 EDT 2011

I recently encountered a problem implementing an undo function in a script. I needed to compare two arrays to see if any values had changed, like this:

put (tArray1 <> tArray2) into sDirtyFlag

so that sDirtyFlag would be true when the arrays failed to match. However, sDirtyFlag was always false! No matter what! 

I put the two arrays into globals and compared them in the message box, like this:

put (gArray1 = gArray2), and the result was always correct. I thought there was some hidden horrible error in my script that dementia prevented me from seeing, until I realized that in my script I was using "<>" not "=" to compare. 

See if the following script, pasted into a button, mystifies you the way it did me. If you comment out the line:

put "xx" into  tTestA2["low2"]

so that the arrays ARE equal you might see, as I did, that the comparison is correct.

Evidently in LiveCode 4.5.3, buildnumber 1444, on MacOS 10.6.8, 

"(tTestA1 <> tTestA2)" is not the same as "not(tTestA1 = tTestA2)" when the arrays are unequal.

(I apologize that the example is so elaborate, I was attempting to reproduce the error environment.)


-- mind the linewraps

on mouseUp
end mouseUp

on DoArrayComparison
    -- create 1 array
    repeat for each item iii in "low1,low2,low3"
        repeat for each item ii in "lower1,lower2,lower3"
            repeat for each item i in "lowest1,lowest2,lowest3"
                put "data" && iii && ii && i into tA1[iii][ii][i]
            end repeat
        end repeat
    end repeat
    -- create 2 arrays from it
    put tA1 into tTestA1
    put tTestA1 into tTestA2
    -- make them unequal
    put "xx" into  tTestA2["low2"]
    -- do three comparisons
    put "(tTestA1 = tTestA2)="& (tTestA1 = tTestA2) &cr& \
            "(tTestA1 <> tTestA2)="& (tTestA1 <> tTestA2)  &cr& \
            "not(tTestA1 = tTestA2)="& not(tTestA1 = tTestA2) 
end DoArrayComparison


Tereza Snyder
Califex Software, Inc.

More information about the Use-livecode mailing list