Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
renojim
Community Streaming Expert

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
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.
0 Kudos
2 REPLIES 2
nowhereman
Visitor

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
renojim
Community Streaming Expert

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! 😉

Thanks nowhereman!
-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.
0 Kudos