Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 13

roList of roAssociativeArray's

I'm trying to create an roList where each element is an roAssociativeArray. My ultimate goal is to have a list where each element is multiple roAssociativeArray's, but I figure if I can't get the simple case to work, the multiple roAssociativeArray issue is hopeless. Anyway, here's my code and its output. Can anybody see where I'm going wrong?
l = CreateObject("roList")
print "New list:";l.Count();" entries"
obj1 = CreateObject("roAssociativeArray")
obj1.str = "one"
obj1.num = 1
l.AddTail(obj1)
obj1.str = "two"
obj1.num = 2
l.AddTail(obj1)
obj1.str = "three"
obj1.num = 3
l.AddTail(obj1)
obj1.str = "four"
obj1.num = 4
l.AddTail(obj1)
print l.Count();" entries"
l.ResetIndex()
for each li in l
print li.str, li.num
end for
Output:
New list: 0 entries
4 entries
four 4
four 4
four 4
four 4

As you can see, all the entries are the same. The same thing happens if the GetHead() and GetTail() functions are used on the roList. Any help would be greatly appreciated.

-JT
0 Kudos
2 Replies
Highlighted
Level 7

Re: roList of roAssociativeArray's

you're overwriting the same roAssociativeArray with each successive set of values. You need to re-initialize obj1 for each new set of values. try this...

l = CreateObject("roList")
print "New list:";l.Count();" entries"
obj1 = CreateObject("roAssociativeArray")
obj1.str = "one"
obj1.num = 1
l.AddTail(obj1)
obj1 = CreateObject("roAssociativeArray")
obj1.str = "two"
obj1.num = 2
l.AddTail(obj1)
obj1 = CreateObject("roAssociativeArray")
obj1.str = "three"
obj1.num = 3
l.AddTail(obj1)
obj1 = CreateObject("roAssociativeArray")
obj1.str = "four"
obj1.num = 4
l.AddTail(obj1)
print l.Count();" entries"
l.ResetIndex()
for each li in l
print li.str, li.num
end for
twitter:nowhereman
http://www.thenowhereman.com/roku
http://www.thenowhereman.com/netflix
0 Kudos
Highlighted
Level 13

Re: roList of roAssociativeArray's

Ah... I get it! I knew it had to be something simple. It always makes me wonder about garbage collection when new objects get created, so I try to just reuse an old one. I can tell you I've overwhelmed the box by creating thousands of objects that were only used for a short time and then discarded. I prefer to do my own memory management! Smiley Wink

Thanks nowhereman!
-JT
0 Kudos