IF Boolean_Logic = Inconsistent Then IsBug()

BlitzMax Forums/BlitzMax Programming/IF Boolean_Logic = Inconsistent Then IsBug()

Okay...

I understand now that 10 = True is comparing 10 to the constant True, and the constant True is 1, so they are not equal.

But it is still confusing and _seemingly_ (though perhaps not actually) inconsistent. From a comparing-one-value-to-another point of view it is consistent, but from a I-want-to-know-if-this-variable-is-true standpoint, it is seemingly inconsistent.

It would seem to me that if this is the case, then writing If X = True or If X = False is bad form, because you want to know if X is True, not if X is = True. While in many cases you might get the result you want because X will equal True when it is true, in many cases X will not equal True when it is true. (true in the sense that "If X" returns true for the value of X.)

So you should never do If X = True, or If X = False, but should instead do If X and If Not X.

Actually, what should probably be done is the opposite... If X should pop up a runtime error if X is not True or False, so that you are instead forced to use the correct form of If X <> 0 or whatever, since it is obviously and integer and not a boolean. I suspect this was not done in C++/Max for backards compatability reasons?

In other words, the format for If should be "If Value:Boolean" and if you attempt to pass an integer to it then it errors. If you want to know if an image exists, then instead of doing "If Image" you'd be forced to do "If Image = Null".

Oh and I've found that this works as expected:
If (Flags&Bit) And (Blah = True) Then Print "true"

Flags&Bit apparently gets converted to a boolean for the purpouse of And.

Hm... Well this has been an interesting discussion. I guess I was wrong about how C does things but in my defense I haven't coded in C in 10 years and If X working while If X = True not working is confusing. I was right about the True = Not False bit being in there, just not when it's used.