Forum Discussion

squirreltown's avatar
squirreltown
Roku Guru
12 years ago

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

3 Replies

  • destruk's avatar
    destruk
    Streaming Star
    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.
  • 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.
  • 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.