Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
Komag
Level 9

Checking Type() is case sensitive - undocumented?

I've noticed that when I check the Type of a variable, it's case sensitive (at least for String/roString). Example:

IF Type(id) = "String" OR Type(id) = "roString" ' Could be either one, depending on custom id or not. ' Otherwise id must be a dummy temp blocker while a diff Mon is moving toward sq
moveMon(TRUE, sy.mr[id], y, x, y2, x2, r2, rm, aa, sy, mAA, cAA) ' Sends tele as TRUE, Mon as sy.mr[id]
ELSE ? "moveAllMon(): At y" y ", x" x ", rm" rm ", trying to be moved: " Type(id) ' It's unlikely a teleCheck() occurs for sq Mon is stepping to, but could happen if tele just turned on
END IF


If I don't capitalize the S in String and roString, it will miss it and think it doesn't match!

I haven't noticed whether this is also true for Integer/roInteger, Array, etc
0 Kudos
33 Replies
TheEndless
Level 7

Re: Checking Type() is case sensitive - undocumented?

Type() returns a string. Directly comparing two strings is always case-sensitive. If you want it to be case-insensitive, you'll need to make sure the case is the same on both sides using UCase or LCase.

For example:
If LCase(Type(id)) = "string" Or UCase(Type(id)) = "ROSTRING" Then
...
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
Komag
Level 9

Re: Checking Type() is case sensitive - undocumented?

Okay, that's helpful to know.

Maybe section 3.7.9 "Comparison Operators" under the strings side for =, could include "true if strings A and B are identical (case sensitive)"
0 Kudos
TheEndless
Level 7

Re: Checking Type() is case sensitive - undocumented?

"Komag" wrote:
Okay, that's helpful to know.

Maybe section 3.7.9 "Comparison Operators" under the strings side for =, could include "true if strings A and B are identical (case sensitive)"

I'm honestly not sure that's necessary. I guess it couldn't hurt, but I can't think of any programming languages that have case-insensitive direct string comparisons.
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
Komag
Level 9

Re: Checking Type() is case sensitive - undocumented?

I'm sure you're right. I've never programmed before, I don't know any languages (BrightScript is my first!) (except for a tiny touch of Lua last year for a mod project for Legend of Grimrock)
0 Kudos
Roku Employee
Roku Employee

Re: Checking Type() is case sensitive - undocumented?

best bet is to use lcase to wrap any string comparisons where case might be an issue or where you have been up for 48 hours programming and might not remember the proper case for something ( is it roUrlEvent or roURLEvent...'yawn' i'll just lcase it... )

if lcase(type(myvariable))="roarray"

if lcase(type(msg))="rourlevent"

- Joel
0 Kudos
Komag
Level 9

Re: Checking Type() is case sensitive - undocumented?

hmm, "rourlevent" sounds like Rourl Event, some sort of lion roar :mrgreen:

Thanks for the tips! Smiley Happy
0 Kudos
TheEndless
Level 7

Re: Checking Type() is case sensitive - undocumented?

"RokuJoel" wrote:
best bet is to use lcase to wrap any string comparisons

If only someone else had suggested that... Smiley Wink
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
Roku Employee
Roku Employee

Re: Checking Type() is case sensitive - undocumented?

Lol.

Oops.

- Joel
0 Kudos
EnTerr
Level 8

Re: Checking Type() is case sensitive - undocumented?

Personally i recommend doing the type check with `getInterface(val, "ifString") <> invalid` instead. It's shorter and faster (just ran some tests - at least 2x faster in general, can be 7x faster if type(val)="roString" in particular).

Best however will be to define a test function for that and use it. That way code is most readable and fn can be updated in the future (or switch between the three different approaches in this thread). Here is mine:
function isString(val):
return getInterface(val, "ifString") <> invalid
end function
0 Kudos