Your Digital Media Has Never Looked So Good

 
btpoole
Topic Author
Posts: 342
Joined: Fri Feb 15, 2013 2:08 pm

roInt & roInteger

Wed Feb 01, 2017 7:39 pm

Really don't know what is going on with this. I have an array that I know contains certain values. I am using a control value that I know exist in the array to search for in the array. The control value types as roInteger. The array element value types as roInt. Like I said, I know the value exist in the particular field. Is it possible that I get a false on my return due to a roInt compared to roInteger? Can a roInt be converted to roInteger?
Thanks
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: roInt & roInteger

Wed Feb 01, 2017 9:17 pm

There is no "roInteger" - there are "Integer" and "roInt", which is a boxed Integer.
Don't worry about it - they completely miscible - for comparison, arithmetics etc
 
btpoole
Topic Author
Posts: 342
Joined: Fri Feb 15, 2013 2:08 pm

Re: roInt & roInteger

Thu Feb 02, 2017 4:45 am

Thanks. If there is no roInteger why does the debugger show roInteger?
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: roInt & roInteger

Thu Feb 02, 2017 9:52 am

btpoole wrote:
Thanks. If there is no roInteger why does the debugger show roInteger?

It does?! Where?
Show a snippet from the console pls
 
btpoole
Topic Author
Posts: 342
Joined: Fri Feb 15, 2013 2:08 pm

Re: roInt & roInteger

Thu Feb 02, 2017 1:28 pm

EnTerr wrote:
btpoole wrote:
Thanks. If there is no roInteger why does the debugger show roInteger?

It does?! Where?
Show a snippet from the console pls

----- Compiling dev 'BETA' ------

------ Running dev 'BETA' runuserinterface ------
RUNUSERINTERFACE
IN USERDATA
IN GetAuthData
USER DATA NOT EMPTY
IN HOME
[DetailsScreen] init
IN ENTRY INT
ENTER LOAD DATA. . .
in roundTime  1486049010
IN P TASK
TASK RAN
IN SETMODE   
DEVICE MODE. . .720p
IN TASK
WEATHER CREATED>>>>>>>>>>  
CHANNEL LIST CONTENT CREATE>>>>>>>>>>>>>>
IN UPDATECONTENT STATUSinvalid
NOW TIME   1486049013
buildtimeslotArray Complete>>  58
buildContent Array Complete>>  1698
NUMBER OF CHANNELS  33
in setGridContent
roInteger
roInteger
roInteger
roInteger
roInteger
roInteger
roInteger
This is from debugger window, didn't copy whole thing. The rointeger is the type of the current time as seconds rounded to nearest half hour. I actually found why my code was failing in the initial question. Thought maybe it had something to do with the types.
 
TaylorAtWild
Posts: 1
Joined: Mon May 29, 2017 2:36 pm

Re: roInt & roInteger

Mon May 29, 2017 2:40 pm

I too have the roInteger data type on an up to date system with software version 7.6.0 build 4125. 

I cannot cast it to a native Integer, which is causing me problems in development. Overall the language has been terrible to develop for and needs major improvements in the core language before I would use it willingly. 

Invalid
 1272
<Component: roArray> =
[
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
    <Component: roAssociativeArray>
]
roInteger
Invalid
 1922
roInteger
Invalid
 1913
roInteger
Invalid
 1909
roInteger
Invalid
 1905
roInteger
Invalid
 1901
roInteger
Invalid
 1896
roInteger
Invalid
 1922
roInteger
Invalid
 1913
roInteger
Invalid
 1909
roInteger
Invalid
 1905
roInteger
Invalid
 1901
roInteger
Invalid
 1896
<Component: roArray> =
[
    false
]

BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.


Current Function:
008:       decoder = JSONDecoder()
009:       json = decoder.decodeJSON(m.shows)
010:       if json <> invalid
011:          m.names = CreateObject("roArray", 10, true)
012:          m.nids = CreateObject("roArray", 10, true)
013:          m.Categories = CreateObject("roAssociativeArray")
014:          for each cat in json.categories
015:                 if type(cat.shows) = "roArray" and cat.shows.Count() <> 0
016:*                    m.Categories[cat.nid] = CreateObject("roAssociativeArray")
017:                     m.names.Push(cat.title)
018:                     m.nids.Push(cat.nid)
019:                     i = 0
020:                     print cat.shows
Type Mismatch. (runtime error &h18) in pkg:/source/loadShows.brs(16)
016:                    m.Categories[cat.nid] = CreateObject("roAssociativeArray")



Above i am trying to cast the roInteger object to an integer using the % mutator.
 
belltown
Posts: 1445
Joined: Thu Dec 09, 2010 1:43 pm
Contact:

Re: roInt & roInteger

Mon May 29, 2017 3:58 pm

Can you post the code that you think is giving you problems.
https://github.com/belltown/
 
User avatar
RokuMarkn
Roku Engineering
Posts: 1582
Joined: Mon Jun 09, 2008 9:20 am

Re: roInt & roInteger

Mon May 29, 2017 4:50 pm

roInteger is just a typo for roInt in the debugger.  There should be no problem converting an object of that type to an integer.  I agree you should post your code; your problem is something different than you think it is.

--Mark
 
renojim
** Valued Community Member **
Posts: 3165
Joined: Mon Feb 15, 2010 1:35 pm

Re: roInt & roInteger

Mon May 29, 2017 9:59 pm

I'm going to guess that cat.nid is a string (or at least not an integer).  Try printing out its type:
print type(cat.nid)
 
User avatar
RokuNB
Posts: 299
Joined: Fri Mar 31, 2017 2:22 pm

Re: roInt & roInteger

Tue May 30, 2017 9:54 am

TaylorAtWild wrote:
011:          m.names = CreateObject("roArray", 10, true)
012:          m.nids = CreateObject("roArray", 10, true)
013:          m.Categories = CreateObject("roAssociativeArray")
014:          for each cat in json.categories
015:                 if type(cat.shows) = "roArray" and cat.shows.Count() <> 0
016:*                    m.Categories[cat.nid] = CreateObject("roAssociativeArray")
017:                     m.names.Push(cat.title)
...

Ok, so a few things:
  1. Come on people, stop doing `CreateObject("roArray", 10, true)` and `CreateObject("roAssociativeArray")` when can say `[ ]` or `{ }`. Not only is this shorter and more readable - but it is actually faster.
  2. I am guessing the above you get an error because you are trying to index roAA with an integer. Unlike other scripting languages however, B/S takes only strings as dictionary keys - so do `m.Categories[cat.nidtoStr()] = {}` above
  3. if you want to check for a type, better to check for capability than type() equaling particular string literal, i.e. `if GetInterface(myVar, "ifInt") <> invalid then ...` - that handles both boxed and unboxed types
 
thanhpham
Posts: 4
Joined: Wed Jun 07, 2017 10:31 pm

Re: roInt & roInteger

Thu Jul 06, 2017 8:52 pm

? type([0][0]) = type(box(0))


In fact, this will print out "false".
The zero wrapped in an array has the type "roInteger" while the boxed zero has the type "roInt".
I am on firmware 7.5.
 
User avatar
Komag
Posts: 677
Joined: Fri Aug 22, 2014 3:42 am

Re: roInt & roInteger

Fri Jul 07, 2017 1:06 pm

Here's what I use:

'======================== TYPE CHECKS =========================
' Apparently all of these are a lot faster than doing something like: IF Type(Th.spriteDraw) <> "roBoolean" ' or: IF Type(id) = "String" OR Type(id) = "roString"
' All these from The Endless: http://forums.roku.com/viewtopic.php?f=34&t=82858&view=unread#p476634
Function IsBoolean(value As Dynamic) As Boolean
    Return GetInterface(value, "ifBoolean") <> INVALID
End Function

Function IsString(value As Dynamic) As Boolean
    Return GetInterface(value, "ifString") <> INVALID
End Function

Function IsArray(value As Dynamic) As Boolean
    Return GetInterface(value, "ifArray") <> INVALID
End Function

Function IsAssociativeArray(value As Dynamic) As Boolean
    Return GetInterface(value, "ifAssociativeArray") <> INVALID
End Function

Function IsInteger(value As Dynamic) As Boolean
    Return GetInterface(value, "ifInt") <> INVALID And (Type(value) = "roInt" Or Type(value) = "roInteger" Or Type(value) = "Integer")
End Function

Function IsFloat(value As Dynamic) As Boolean
    Return (GetInterface(value, "ifFloat") <> INVALID Or (Type(value) = "roFloat" Or Type(value) = "Float"))
End Function

Function IsDouble(value As Dynamic) As Boolean
    Return (GetInterface(value, "ifDouble") <> INVALID Or (Type(value) = "roDouble" Or Type(value) = "roIntrinsicDouble" Or Type(value) = "Double"))
End Function

Function IsList(value As Dynamic) As Boolean
    Return GetInterface(value, "ifList") <> INVALID
End Function

Function IsDateTime(value As Dynamic) As Boolean
    Return (GetInterface(value, "ifDateTime") <> INVALID Or Type(value) = "roDateTime")
End Function

Function IsXmlElement(value As Dynamic) As Boolean
    Return GetInterface(value, "ifXMLElement") <> INVALID
End Function

Function IsFunction(value As Dynamic) As Boolean
    Return GetInterface(value, "ifFunction") <> INVALID
End Function

Function IsHttpAgent(value As Dynamic) As Boolean
    Return GetInterface(value, "ifHttpAgent") <> INVALID
End Function
 
User avatar
RokuNB
Posts: 299
Joined: Fri Mar 31, 2017 2:22 pm

Re: roInt & roInteger

Tue Jul 11, 2017 6:34 pm

thanhpham wrote:
? type([0][0]) = type(box(0))

In fact, this will print out "false".
The zero wrapped in an array has the type "roInteger" while the boxed zero has the type "roInt".
I am on firmware 7.5.

So it does, it's a bug or a feature.
Don't check for type() = string, instead check getInterface(x, "roInt") <> invalid - will work for all kind of ints.
Brightscript Debugger> for each i in [1, [1][0], box(1), 1.0]: ? i, type(i), type(i, 3), getInterface(i, "ifInt") <> invalid: next 
 1              roInteger       Integer         true
 1              roInteger       Integer         true
 1              roInt           roInt           true
 1              roFloat         Float           false

Who is online

Users browsing this forum: No registered users and 5 guests