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: 
btpoole
Channel Surfer

Multi Dimensional Array

Not sure if I am doing this right. I am creating a multidimensional array like:

Videoinfo={
vid: videoid,
vtitle: videotitle,
vdate: videodate,
vtime: videotime
}


This works to populate the arrary but not exactly. If I ?videoinfo.vid , videoinfo.vtitle, videoinfo.vdate or videoinfo.vtime I get the entire list each. I need to extract or print a single instance for example:
If I have the following and push it to the array videoinfo along with 10 other groups like the one below.
videoid= 5
videotitle="My Video"
Videodate= 12/01/14
videotime= 1:00

Now I only want the first group in the array so,
?videoinfo[0].vid
?videoinfo[0].vtitle
?videoinfo[0].vdate
?video[0].vtime
or change the index to any number to print or extract that group. When I try to print using an idex I get a type mismatch.

Thanks
0 Kudos
2 REPLIES 2
RokuMarkn
Visitor

Re: Multi Dimensional Array

I may not be understanding completely, but it sounds like what you want isn't a multidimensional array (an array of arrays), but rather an array of Associative Arrays.


videoinfo = []
video1 = {
vid: videoid,
vtitle: videotitle,
vdate: videodate,
vtime: videotime
}
videoinfo.Push(video1)
video2 = ...
videoinfo.Push(video2)
... etc

print videoinfo[0].vtitle
print videoinfo[1].vtitle


--Mark
0 Kudos
btpoole
Channel Surfer

Re: Multi Dimensional Array

Mark
Thanks for the help on this. I have done as suggested and works great but it leads to a problem. I was under impression that once an array was created, its value remained set until changed. What I mean is the following. Within a function I have several conditional statments. In the first m.xmlexist=0, the code will run when the channel loads, executes correctly and sets m.xmlexist=1, so the next conditional statement will run directly after the initial. All this works perfect. After the channel has loaded and the roArray programlist has been created nothing changes the value of programlist array. When a selection is made with the remote, a function is called that sets the value of m.xmlexit=2. The function is called, the m.xmlexist=0 and =1 is passed over, the execution enters the third conditional statment correclty but the roArray programlist.count() throws a Dot operator error as if the programlist roarray has not been established. The roArray was created in the second conditional statment and shows to be populated. Once the code proceeds thru the function the first time, is the value of the roArray "forgotten"? I thought once it was established I could call it back within the same function and it retain value. I maybe really missing something. From database programming I was seeing the roArray created was kinda like a recordset that was created from xml file. I was doing it like this so the complete xml file didn't have to parsed each time a selection was made, only the roArray programlist. Thanks for any advice

If m.xmlexist=0
procedure carried out
m.xmlexist=1
End if
If m.xmlexist=1
programlist=[]
programinfo=[]
For i= 0 to xml.programme.count()-1
programinfo={
date: xml.programme[i]@start,
time: xml.programme[i]@start,
title: xml.programme[i].title.gettext()
channel: xml.programme[i]@channel 'GET CHANNEL
}
?"SHOW DATE. .."programinfo.date
?"SHOW TIME. . ."programinfo.time
?"SHOW TITLE. . ."programinfo.title
?"SHOW CHANNEL. . ."programinfo.channel
programlist.Push(programinfo)
End For
?"PROGRAMLIST CREATED. . ."
?"PROGRAMLIST COUNT. . ."programlist.count()
End if
If m.xmlexist=2
?"PROGRAMLIST COUNT. . ."programlist.count()
End if
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.