|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Fri Jun 25, 2010 11:55 pm
[320B] (Mis)Understanding Booleans |
I have several external applications that return boolean values and I am having problems working with them. This problem is not specific to release 3.20 (or 3.21) but I feel it needs to be addressed.
So here is what I do:
Code: |
comState = %comget( @comRef, isOpen)
|
Here is what comRef has:
Code: |
Variable: + comRef (Auto) comsql
Variable: + comsql (Auto) <COMObject>
Variable: + comState (Auto) True
|
So far, so good. But when I run this simple test from the command line:
Code: |
#IF (@comState = "True") {#ECHO "TRUE"} {#ECHO "FALSE"}
|
For the sake of completeness, I tried it this way also:
Code: |
#IF (@comState = True) {#ECHO "TRUE"} {#ECHO "FALSE"}
|
Lastly, I tried this:
Code: |
#IF (@comState) {#ECHO "TRUE"} {#ECHO "FALSE"}
|
In the first 2 cases FALSE prints to the screen. I the last case TRUE prints to the window because comState evaulates to a not-zero.
My question is: How can the boolean return from the external application be interpreted correctly? |
|
_________________ Sic itur ad astra.
Last edited by Anaristos on Sat Jun 26, 2010 3:29 am; edited 2 times in total |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Jun 26, 2010 12:00 am |
Does @comState have the "string" value of True? If so, then you need to test against the string value like:
Code: |
#IF (@comState = "True") {#ECHO "TRUE"} {#ECHO "FALSE"} |
In CMUD, True without the quotes is the same as 1 and False without the quotes is the same as 0 (zero).
Once again, people need to be more careful with including " quotes around string values. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Jun 26, 2010 12:03 am |
Btw, this is even MORE IMPORTANT now in v3.21 with the changes to handle expressions properly. For example, look at this:
Code: |
a = 1
#SHOW %if(@a=1,true,false)
#SHOW %if(@a=2,true,false) |
In past versions of CMUD, this would display "true" and "false" because %if was improperly treating arguments as strings instead of expressions. In 3.21, the True and False results are properly handled as expressions, so 3.21 displays 1 and 0 respectively.
If you want to return the *string* value instead of the expression, you put " quotes around the strings, like this:
Code: |
#SHOW %if(@a=1,"true","false") |
|
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Sat Jun 26, 2010 12:05 am |
comState is set to AUTO and that is the problem. I don't know what the vartype is. But I've tried both "True" and True and neither works. I've been using #IF because %if has been very unreliable.
|
|
_________________ Sic itur ad astra. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Jun 26, 2010 12:10 am |
OK, I see the issue now. It's a COM issue. The "True" that is returned is a COM Boolean value and somehow that isn't getting converted with AutoType properly.
For testing in a blank session, I did this:
Code: |
a=123
test=%session.varnum(0).enabled
#if (@test = "True") {#show "true"} {#show "false"} |
and it showed false even though "#var test" shows it is true.
I've added this to the bug list for next week. |
|
|
|
|
|