Error going back in multi-level GridScreen

I am developing a Multi-level(like folders with subfolders or files in it) app with GridScreen, that can have Sub-gridscreen (with videos) or just the Video Files depending on the variable getContent=“Yes” or “No” .
If the getContent=“yes” then I am calling ShowGridScreen within itself again when the item is selected. And it works Great. But the problem is , when I pressed the GoBack button on roku, it goes to the previous Grid but throws an error on
return -1
and then nothing works, I cannot select any videos/folders again.

Can you tell me what am I doing wrong ?

Function showGridScreen(screen As Object,SourceURL as string) As string

    categoryList = getCategoryList(SourceURL)
    screen.setupLists(categoryList.count())
    screen.SetListNames(categoryList)
    showArray = []
    
        for i = 0 to categoryList.count()-1
            channels = getShowsForCategoryItem(SourceURL,categoryList[i])
            showArray[i] = channels
            screen.SetContentList(i, channels)
        end for
    screen.Show()
    
    while true
         msg = wait(0, m.port)
         if type(msg) =  "roGridScreenEvent" then
             if msg.isScreenClosed() then
                 return -1
             else if msg.isListItemFocused()
                  print "Focused On: " + showArray[msg.GetIndex()][msg.GetData()]["title"]
             else if msg.isListItemSelected()
					print "Selected: " + showArray[msg.GetIndex()][msg.GetData()]["title"]
					getcontent=showArray[msg.GetIndex()][msg.GetData()]["GetContent"]
                
                if  getcontent="Yes" then
                    print "We Need to retrieve Content"
                    newURL=showArray[msg.GetIndex()][msg.GetData()]["StoredURL"]
                    print newURL
                    newScreen = preShowGridScreen()
                    showGridScreen(newScreen,newURL)
                else 
                    print "No need to Grab Content, Playing Video"
                    showVideoScreen( showArray[msg.GetIndex()][msg.GetData()])
                endif
             endif
         endif
    end while

end function
Function showGridScreen(screen As Object,SourceURL as string) As string

return -1

You can’t return an Integer from a function with a return type of String. You have to either return a string, e.g. “”, or change the function’s return type, e.g. Dynamic, making sure that the caller of the function can handle whatever is returned.

Thankx, return -1 changed to return “” and the error is gone.

Now I press the GoBack button at Level 2 Grid Screen, there is no error and the Level 1 GridScreen is shown, but I cannot select any of the items there. It appears that I exited all the loops.


while true
         msg = wait(0, m.port)

Any idea why is this happening ?

Bump

    while true
         msg = wait(0, m.port)
         if type(msg) =  "roGridScreenEvent" then
             if msg.isScreenClosed() then
                 return ""

so when msg.isScreenClosed is triggered, thats when it exits the while loop . How do I fix it ?

BUMP!

Can somebody help me on this issue.

  1. Your showGridScreen function doesn’t seem like it needs to return anything, so don’t; just declare the return type with As Void.
  2. Replace the Return -1 or Return “” statement in your while loop with exit while.
  3. Don’t share message ports between your recursively-called grid screen functions. Instead, at the start of showGridScreen, use: port = CreateObject (“roMessagePort”) and screen.SetMessagePort (port), then replace all occurrences of m.port with port.

Number 3 is your main problem, but the others are worth addressing to make your code more understandable.

^ Thank you Very much. It solved my problem.