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:
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?
“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.
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.
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).