renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010
04:43 PM
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?
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
l = CreateObject("roList")Output:
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
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.
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.
2 REPLIES 2
nowhereman
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010
04:47 PM
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
http://www.thenowhereman.com/roku
http://www.thenowhereman.com/netflix
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010
05:11 PM
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
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.
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.