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: 
squirreltown
Roku Guru

For each

I am trying to draw a list using a for/each statement with multiple variables. What i am getting is each of ten items drawn in each of ten slots, where i want one item in each slot.
Is this possible? I am not seeing it yet.

		for i = 0 to 9
for n = 1 to 10
for p = 211 to 589 step 42

m.screen.drawtext( n.toStr()+")" , 810, p, grey, font6) 'playlist:
m.screen.drawtext( m.item[i]["title"] ,850, p, grey, font6) ' song title

end for
end for
end for


Thanks
Kinetics Screensavers
0 Kudos
4 REPLIES 4
gonzotek
Visitor

Re: For each

"squirreltown" wrote:
I am trying to draw a list using a for/each statement with multiple variables. What i am getting is each of ten items drawn in each of ten slots, where i want one item in each slot.
Is this possible? I am not seeing it yet.

		for i = 0 to 9
for n = 1 to 10
for p = 211 to 589 step 42

m.screen.drawtext( n.toStr()+")" , 810, p, grey, font6) 'playlist:
m.screen.drawtext( m.item[i]["title"] ,850, p, grey, font6) ' song title

end for
end for
end for


Thanks

Not sure what you're trying to do exactly, but does this help? It doesn't look like you need three loops, although you might need two, depending on what it is supposed to do.

p_array = [211, 253, 295, 337, 379, 412, 463, 505, 547, 589]
for i = 0 to 9
m.screen.drawtext((i+1).toStr()+")", 810, p_array[i], grey, font6) 'playlist:
m.screen.drawtext(m.item[i]["title"], 850, p_array[i], grey, font6) 'song title
end for
If not, can you share more of the channel (perhaps a pared down runnable example)?
Remoku.tv - A free web app for Roku Remote Control!
Want to control your Roku from nearly any phone, computer or tablet? Get started at http://help.remoku.tv
by Apps4TV - Applications for television and beyond: http://www.apps4tv.com
0 Kudos
destruk
Streaming Star

Re: For each

Why can't you use a single loop?

for i = 0 to 9
n=i+1
p=i*42+211
m.screen.drawtext( n.toStr()+")" , 810, p, grey, font6) 'playlist:
m.screen.drawtext( m.item["title"] ,850, p, grey, font6) ' song title
next

Your original code is probably too complex, but this will do what you need it to.
Gonzotek's code should work too.
0 Kudos
squirreltown
Roku Guru

Re: For each

gonzotek - Thank you! I think that should work, I'll give it a try.
All I'm really trying to do is reduce the amount of code on the page. This is for an audioplayer on a roscreen which displays the playlist, either 10 of thirty items so its just a massive amount of stuff to scroll through all the time while working on it. I currently have the playlists offloaded into other functions, but of course that makes the redrawing real slow and that code will have to come back into the main function eventually, so less is better.
Thanks again.

destruk - Thank you for that - I tried it that way but not quite exactly and it didn't work so I questioned if it was possible, turns out it was bad syntax as usual. I will try this way too, it seems yours and gonzotek's are two good solutions to the same problem.
Kinetics Screensavers
0 Kudos
gonzotek
Visitor

Re: For each

I'd probably go with destruk's version after all is said and done. It'll be easier to adjust if the spacing ever needs to be changed.
Remoku.tv - A free web app for Roku Remote Control!
Want to control your Roku from nearly any phone, computer or tablet? Get started at http://help.remoku.tv
by Apps4TV - Applications for television and beyond: http://www.apps4tv.com
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.