Page 1 of 1

Error in an inequality

Posted: Tue Sep 04, 2012 6:21 pm
by Korbedda
Hi, if I compare an error with a number (SendSysMessage(me, CStr(error < 1))), the result is random, sometimes 0 and sometimes 1. I would expect the result to be an error or zero.

Re: Error in an inequality

Posted: Mon Sep 17, 2012 9:50 pm
by kevin
Looks like error and struct both do not have operators defined for those arithmetic operations (<, <=, >, >=, etc) so they only compare the memory addresses of those variables, which would make sense for your "randomness".

From a brief glance at the code:

x < y:
If x is Long:
--- If y is Long or Double, then return the normal expected value of numeric x < numeric y.
--- Otherwise, ALWAYS return false.
If x is Error (or Struct, or any other object that does not have isLessThan defined):
--- Return memory address location of x < memory address location of y => unknown results

Re: Error in an inequality

Posted: Sat Sep 22, 2012 2:30 pm
by Korbedda
Okay, thanks, here's why I think it should be fixed. In eScript many error catches are done by error propagation, like in this case:

Code: Select all

if (GetSomething(someone).getprop(some true/false parameter))
    do something
endif
If there is something wrong with the input, something doesn't exist, the result is an error. So you just write the condition and if there's anything wrong on the way, you expect the result to return an error. It allows for more compact code by putting multiple error checks together. It is used quite often and I came to rely on this, as many other may have. It just doesn't work for inequalities. That is why I am pointing this out.