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

If / End If still biting me on the butt

I"m pretty sure I have the correct amount of End If's here, but whenever I save it I get a syntax error for the End While line. If I tack three End If's on the end before the end while, then the error goes away, but I become more confused. I just started re-writing my app all over again and this is really frustrating me. Wish there was some proper "Unterminated If on Line #X" error messages from the compiler.

There may be other issues in this code, but I'm only concerned about writing proper if then else else if end if statements.

function posterscr(posterlist as object) as object

poster.SetListDisplayMode("best-fit")
poster.SetContentList(PosterList)

' if isauthenticated then
' categories=["Search","Explore", "Tracks", "About","You"]
' else
categories=["Search","Explore"," Tracks","About"]
' end if

poster.SetListNames(categories)
poster.SetListStyle("flat-category")
poster.SetListDisplayMode("best-fit")
poster.SetFocusedList(0)
poster.SetFocusedListItem(0)
poster.show()

while true

msg=wait(0,port)
msgtype=type(msg)
message=msg.getmessage()
idx = msg.GetIndex()

if type(msg) = "roPosterScreenEvent" then


if msg.isScreenClosed() then
print "screen closed exit app"
return -1
end if

if msg.islistSelected() and idx=5 and isauthenticated=false then
authenticate()
return -1
end if

if msg.isListFocused() then
m.currentcategory=idx ' assign category to global variable
'figure out which category was selected
if idx = 0 then
print "search selected"
' handle search section selected
else if idx = 1 then
print "explore selected"
'handle explore section selected


else if idx = 2 then
print "top tracks selected"
'handle top tracks selected
'call display top tracks
else if idx = 3 then
print "about this app selected"
'show the about screen
end if
end if

if msg.isListItemSelected() then

if m.currentcategory = 0 then 'we are in search section
if idx = 0 then
posterlist.Append(searchTracks())
end if

if idx = 1 then
posterlist.Append(searchPeople())
end if

if idx = 2 then
posterlist.Append(searchGroups())
end if

if idx = 3 then
posterlist.Append(searchGenre())
end if

else
if m.currentcategory=1 then 'we are in Explore section
print "explore section bla bla"
else if m.currentcategory=2 then 'we are in Hot section
posterlist.SetContentList(GetHotStuff())
else if m.currentcategory=3 then 'we are in about section
posterlist.setContentList(About())
else if m.currentcategory=4 then 'we are in you section
print "its all you babe"
end if
end if
end while

end function
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: If / End If still biting me on the butt

You have two issues that I see. First is on line 80. That "If" should be on the same line as the "Else" preceding it. Second is on line 90. You need an "End If" there to close the main "If type()" if/then.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos

Re: If / End If still biting me on the butt

Didn't have a chance to test it, but see if this doesn't work for you. Just cleaned up a few items that i noticed with some formatting...

function posterscr(posterlist as object) as object

poster.SetListDisplayMode("best-fit")
poster.SetContentList(PosterList)

' if isauthenticated then
' categories=["Search","Explore", "Tracks", "About","You"]
' else
categories=["Search","Explore"," Tracks","About"]
' end if

poster.SetListNames(categories)
poster.SetListStyle("flat-category")
poster.SetListDisplayMode("best-fit")
poster.SetFocusedList(0)
poster.SetFocusedListItem(0)
poster.show()

while true

msg=wait(0,port)
msgtype=type(msg)
message=msg.getmessage()
idx = msg.GetIndex()

if type(msg) = "roPosterScreenEvent" then
if msg.isScreenClosed() then
print "screen closed exit app"
return -1
else if msg.islistSelected() and idx=5 and isauthenticated=false then
authenticate()
return -1
else if msg.isListFocused() then
m.currentcategory=idx ' assign category to global variable
'figure out which category was selected
if idx = 0 then
print "search selected"
' handle search section selected
else if idx = 1 then
print "explore selected"
'handle explore section selected
else if idx = 2 then
print "top tracks selected"
'handle top tracks selected
'call display top tracks
else if idx = 3 then
print "about this app selected"
'show the about screen
end if
else if msg.isListItemSelected() then
if m.currentcategory = 0 then 'we are in search section
if idx = 0 then
posterlist.Append(searchTracks())
else if idx = 1 then
posterlist.Append(searchPeople())
else if idx = 2 then
posterlist.Append(searchGroups())
else if idx = 3 then
posterlist.Append(searchGenre())
end if
else
if m.currentcategory=1 then 'we are in Explore section
print "explore section bla bla"
else if m.currentcategory=2 then 'we are in Hot section
posterlist.SetContentList(GetHotStuff())
else if m.currentcategory=3 then 'we are in about section
posterlist.setContentList(About())
else if m.currentcategory=4 then 'we are in you section
print "its all you babe"
end if
end if
end if
end if
end while

end function
--
Float Left Interactive Team
www.floatleftinteractive.com
0 Kudos
jbrave
Channel Surfer

Re: If / End If still biting me on the butt

Wow, there were a few things in there that were problems, thanks for all the helpful suggestions. It is sooooo easy to make mistakes with IF/THEN/ELSE statements, mostly stupid things like accidentally putting the Then on the next line which are really hard to see.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
kbenson
Visitor

Re: If / End If still biting me on the butt

Consistent indentation helps a lot. Note in your first example that the end while and end function are two levels of indentation away, instead of one. That's a dead ringer that you wither didn't indent/unindent correctly at a point, or are missing a block closing statement.

I find what helps me most, in any language, is to immediately write the block's ending statement after writing the opening, and then moving up and indenting to write in the complete block I just created. That way, I never have to remember to close a block, just to move past the existing close statement, which is easy to see.
-- GandK Labs
Check out Reversi! in the channel store!
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.