?true=1
true
?false=0
false
?1+false
Type Mismatch
any way to get the numeric value of a boolean short of writing an if-then statement?
?true=1
true
?false=0
false
?1+false
Type Mismatch
any way to get the numeric value of a boolean short of writing an if-then statement?
There’s nothing in the SDK that I’m aware of, but I use a simple immediate if function for this kind of thing…
Function IIf( Condition As Boolean, Result1 As Dynamic, Result2 As Dynamic ) As Dynamic
If Condition Then
Return Result1
Else
Return Result2
End If
End Function
Used like…
?IIf( True, 1, 0 )
Yeah, I was just hoping… a few languages let you treat true/false as 1/0, and you can save a few lines of code that way.
I can’t test it right now, but I’m pretty sure BrightScript treats 1 and 0 as true and false, but not the other way around.
Ok, just tested, and I can confirm that 0 evaluates to false, and everything else evaluates to true.