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: 
Yoglets
Newbie

possible bug in roMessagePort.wait()

This is the shortest code I've been able to get to duplicate the issue.


Sub Main()
u = getStringFromKeyboard("Enter username")
p = getStringFromKeyboard("Enter password")
End Sub

Function getStringFromKeyboard(message = "" As String) As String
result = ""
port = CreateObject("roMessagePort")
screen = CreateObject("roKeyboardScreen")
screen.SetMessagePort(port)
screen.SetDisplayText(message)
screen.AddButton(1, "OK")
screen.Show()
while true
print "waiting..."
msg = wait(0, port)
print "done waiting"
if type(msg) = "roKeyboardScreenEvent" then
if msg.GetIndex() = 1 then
result = screen.GetText()
exit while
end if
end if
end while
screen.Close()
return result
End Function


Running this app, I get prompted for a username, I enter the username and hit ok, then I get booted back to the main menu. The second keyboard screen (for the password) never appears. The debug output shows:


waiting...
done waiting
waiting...


I.e., it's crashing on the second call to wait(). Am I doing something wrong or is this a platform bug?
0 Kudos
2 REPLIES 2
gonzotek
Visitor

Re: possible bug in roMessagePort.wait()

"Yoglets" wrote:
This is the shortest code I've been able to get to duplicate the issue.


Sub Main()
u = getStringFromKeyboard("Enter username")
p = getStringFromKeyboard("Enter password")
End Sub

Function getStringFromKeyboard(message = "" As String) As String
result = ""
port = CreateObject("roMessagePort")
screen = CreateObject("roKeyboardScreen")
screen.SetMessagePort(port)
screen.SetDisplayText(message)
screen.AddButton(1, "OK")
screen.Show()
while true
print "waiting..."
msg = wait(0, port)
print "done waiting"
if type(msg) = "roKeyboardScreenEvent" then
if msg.GetIndex() = 1 then
result = screen.GetText()
exit while
end if
end if
end while
screen.Close()
return result
End Function


Running this app, I get prompted for a username, I enter the username and hit ok, then I get booted back to the main menu. The second keyboard screen (for the password) never appears. The debug output shows:


waiting...
done waiting
waiting...


I.e., it's crashing on the second call to wait(). Am I doing something wrong or is this a platform bug?
Create a facade screen. The roku exits the app immediately after the last screen is closed. You create the first keyboard screen and also close it in the getStringFromKeyboard function, and since there are no other screens open at that moment, that's when the Roku kills the app. See RokuKevin's explanation here: viewtopic.php?p=162550#p162550 (note: he refers to 'screen flickering', which may have been true when he wrote it, but nowadays it's a requirement to have a screen always stuck open at the back of your stack for the life of your app: viewtopic.php?p=321402#p321402).
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
Yoglets
Newbie

Re: possible bug in roMessagePort.wait()

Excellent! Thank you gonzotek.
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.