Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jbrave
Channel Surfer

convert boolean to int?

?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?
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: convert boolean to int?

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 )
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jbrave
Channel Surfer

Re: convert boolean to int?

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.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
TheEndless
Channel Surfer

Re: convert boolean to int?

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.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
TheEndless
Channel Surfer

Re: convert boolean to int?

Ok, just tested, and I can confirm that 0 evaluates to false, and everything else evaluates to true.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos