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: 
brocker
Visitor

Storing an Associative Array in a AssociativeArray

Hey All,

I'm trying to store an Associative Array within a Associative Array with code similar to the following:



Function SetValues() As Object

'Create AA
aa_StudioData = CreateObject("roAssociativeArray")
aa_PosterItems = CreateObject("roAssociativeArray")

'Populate Items
aa_PosterItems.Value1 = "Foo"
aa_PosterItems.Value2 = "Foo2"
aa_PosterItems.Value3 = "Foo3"

'Populate
aa_StudioData.Count = 3
aa_StudioData.AA = aa_PosterItems

'Return Populated AA
Return aa_StudioData

End Fuction

Sub GetValues()

'Create AA
aa_Populated = CreateObject("roAssociativeArray")
aa_StudioDataList = CreateObject("roAssociativeArray")

'Populate AA List
aa_Populated = SetValues()
aa_StudioDataList = aa_Populated.AA

If aa_StudioDataList = invalid Then
Print("Invalid") <<==== ALWAYS HITS
End If

End Sub


But when I get the Associative Array back, and try to use the ".AA", it is giving me a type of "INVALID". Is what I'm doing possible?

Thanks
Bud
0 Kudos
6 REPLIES 6
RokuChris
Roku Employee
Roku Employee

Re: Storing an Associative Array in a AssociativeArray

You can certainly assign an AA as an attribute of another AA. The code you posted works for me in 3.0 and 4.1. At the end of GetValues(), aa_StudioDataList is an AA that looks like this...

{Value1: "Foo", Value2: "Foo2", Value3: "Foo3"}
0 Kudos
brocker
Visitor

Re: Storing an Associative Array in a AssociativeArray

Thanks Chris,

One thought, do you think it would make a difference if one of the values in the AA is a "roArray"? Would that corrupt anything? One of the other items I store is a roArray (just didn't include it with the sample code).

I did notice if I did a "For Each" loop like the following:


For Each item in aa_StudioDataList
Print(item)
End For


It prints the item name, but how would I parse through each value in the AA to find what I'm looking for? Everything I've tried comes back as "INVALID".

Any thoughts

Thanks
Bud

PS - I forgot to mention I'm running 4.1 on the Roku 2.
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Storing an Associative Array in a AssociativeArray

Have you tried the Lookup() function?


For Each item in aa_StudioDataList
Print item + ":" + aa_StudioDataList.Lookup(item)
End For
0 Kudos
brocker
Visitor

Re: Storing an Associative Array in a AssociativeArray

Yeah, I get a "Type Mismatch" error.

I was thinking that I get this because the AA is INVALID when I run a check on the object as follows


If aa_StudioDataList = invalid Then
Print("INVALID")
End If


If the compiler doesn't recognize the aa_StuidioDataList as a AA, then trying to do the "Lookup()" would throw an error wouldn't it?

Thanks
Bud
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Storing an Associative Array in a AssociativeArray

"brocker" wrote:
If the compiler doesn't recognize the aa_StuidioDataList as a AA, then trying to do the "Lookup()" would throw an error wouldn't it?


Actually, if aa_StuidioDataList were invalid, I'm pretty sure you'd get something like "dot operator attempted with invalid object". If you're getting a type mismatch, something else must be going wrong. Using the code in your OP, aa_StuidioDataList does end up being an AA and the Lookup() method works.
0 Kudos
brocker
Visitor

Re: Storing an Associative Array in a AssociativeArray

Really strange, well I guess it's good to know that what I'm trying to do is possible, but something is amiss. I'll go back and verify what I'm doing, I prob did some silly thing somewhere.

Thanks for your help Chris, I'll post back with any findings or further clarifications.

Regards
Bud
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.