renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
10:23 AM
Iterating over roAssociativeArray reboots Roku
I'm working on someone else's code who adds a bunch of things to an roAssociativeArray. Rather than try to go through the code and see what all gets added, I thought I'd just try to print it out. All I've done is come up with a couple of ways to reboot the Roku. My first attempt was:
I didn't know what to expect from the 'print y', but it drops into the debugger with a "Non printable value" error. I wasn't too surprised, but I was surprised at what happened when I replaced the 'print y' with 'print "y"'. It prints out five y's, the telnet connection is lost and the Roku DVP reboots. My next attempt was:
The same thing happens: 5 y's, lost telnet connection, reboot.
So I guess I have two questions. Should this cause a reboot and how do I iterate over an roAssociativeArray and print out the key/value pairs?
-JT
x = createObject("roAssociativeArray")
x.AddReplace("key 1", "val 1")
x.AddReplace("key 2", "val 2")
x.AddReplace("key 3", "val 3")
x.AddReplace("key 4", "val 4")
y = x.Reset()
while y <> invalid
print y
y = x.Next()
end while
I didn't know what to expect from the 'print y', but it drops into the debugger with a "Non printable value" error. I wasn't too surprised, but I was surprised at what happened when I replaced the 'print y' with 'print "y"'. It prints out five y's, the telnet connection is lost and the Roku DVP reboots. My next attempt was:
x = createObject("roAssociativeArray")
x.AddReplace("key 1", "val 1")
x.AddReplace("key 2", "val 2")
x.AddReplace("key 3", "val 3")
x.AddReplace("key 4", "val 4")
y = x.Reset()
while not x.IsEmpty()
print "y"
y = x.Next()
end while
The same thing happens: 5 y's, lost telnet connection, reboot.
So I guess I have two questions. Should this cause a reboot and how do I iterate over an roAssociativeArray and print out the key/value pairs?
-JT
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
8 REPLIES 8
TommyTheKid
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
10:29 AM
Re: Iterating over roAssociativeArray reboots Roku
Probably should be foreach y in x ?
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
11:11 AM
Re: Iterating over roAssociativeArray reboots Roku
We have a winner! Now, do you know how to print out the key/value pairs?
Oops! I should have just tried it. That works, I can print y. Any idea why the other ways crash?
Thanks!
-JT
Oops! I should have just tried it. That works, I can print y. Any idea why the other ways crash?
Thanks!
-JT
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
TommyTheKid
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
04:04 PM
Re: Iterating over roAssociativeArray reboots Roku
"renojim" wrote:
We have a winner! Now, do you know how to print out the key/value pairs?
Oops! I should have just tried it. That works, I can print y. Any idea why the other ways crash?
Thanks!
-JT
It should NOT crash, that is a bug.
I think the ".Next" operator works on lists, not arrays?
hoffmcs
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
04:58 PM
Re: Iterating over roAssociativeArray reboots Roku
"renojim" wrote:
We have a winner! Now, do you know how to print out the key/value pairs?
Oops! I should have just tried it. That works, I can print y. Any idea why the other ways crash?
Thanks!
-JT
In the register example from the SDK, there are some great general methods to print out different data structures. Look in the generalUtils.brs file, specifically PrintAA for printing out the key value pairs.
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
10:08 PM
Re: Iterating over roAssociativeArray reboots Roku
"TommyTheKid" wrote:
I think the ".Next" operator works on lists, not arrays?
The reason I thought the ".Next" operator should work is because the documentation for roAssociativeArray says it implements the ifEnum interface.
-JT
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
10:09 PM
Re: Iterating over roAssociativeArray reboots Roku
"hoffmcs" wrote:
In the register example from the SDK, there are some great general methods to print out different data structures. Look in the generalUtils.brs file, specifically PrintAA for printing out the key value pairs.
Thanks for the tip!
-JT
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
TommyTheKid
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
10:55 PM
Re: Iterating over roAssociativeArray reboots Roku
10.2 ifEnum
Reset() As Void
• Reset position to first element of enumeration
Next() As Object
• Return Object at current position and increment position
IsNext() As Boolean
• Return true if there is a next element
IsEmpty() As Boolean
• Return true is there is not a next element
(edited the spacing because the PDF guides don't paste well)
(snip)
10.13 roAssociativeArray
An associative array (also knows as a map, dictionary or hash table) allows objects to be associated with string keys. The roAssociativeArray class implements the ifAssociativeArray and ifEnum interfaces.
Just letting you know that your code of x.next() is valid brightscript, but yea "printAA(x)" works soo much nicer. Its in the examples (many of them).
~tommy

RokuKevin
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2010
09:25 AM
Re: Iterating over roAssociativeArray reboots Roku
We should never crash the firmware with bugs in BrightScrip.... I've opened a bug on this.
--Kevin
--Kevin