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
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
Thanks. If there is no roInteger why does the debugger show roInteger?
“btpoole” wrote:
Thanks. If there is no roInteger why does the debugger show roInteger?
It does?! Where?
Show a snippet from the console pls
“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.
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.
Can you post the code that you think is giving you problems.
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
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)
“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:
-
Come on people, stop doing
CreateObject("roArray", 10, true)andCreateObject("roAssociativeArray")when can say[ ]or{ }. Not only is this shorter and more readable - but it is actually faster. -
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 -
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
? 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.
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
“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
