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: 
DLC
Visitor

Help for begginer

Hello everybody,

I am in engineering school, I am working on the roku system for an internship and i need a little help.

First, I have created a roPosterScreen with a roDialogMessage and buttons. I managed to get different actions when i click on the buttons, but i would like to change the layout, so to move the buttons, changed the font and color of the text, etc. I looked for the AddButton() function in all components, and i have always found :
"The buttons are displayed in a standard location on the screen and appear in the order added". Is it really impossible to create a custom button?

Then, I have downloaded the SDK and the videoplayer sample is working fine, so i would like to modify it a little. I copied the appMain.brs in another text file that i named appSecond.brs, and changed the name of the function the same way, so it is now called second(). I created a new appMain.brs file with a roPosterScreen, a roDialogMessage and a button. When i click on the button, i want to open the sample as it was before i changed it, so i simply call the function second(). The problem is that the back button on the remote doesn't work anymore. I can navigate through the channels and launch one, but i have to click "Home" to come back, and I don't understand why, as i didn't change anything in the sample code, except the name of the function that starts the sample.
Can anyone help me please?

Thank you.

Denis
0 Kudos
32 REPLIES 32
RokuJoel
Binge Watcher

Re: Help for begginer

You need to properly handle the msg.isScreenClosed() event, usually like:

...
else if msg.isscreenclosed() then
return -1
else if ....


isScreenClosed() is the event that fires when you hit the back button.

If you want custom buttons you'll have to work with roImageCanvas, or roScreen and create your own UI.

- Joel
0 Kudos
DLC
Visitor

Re: Help for begginer

I have this in my code :

if type(msg) = "roPosterScreenEvent"
if (msg.isScreenClosed()) then
screen.Close()
end if


What is the difference with "return -1" ?

As for the buttons, i managed to change the colors using the roAppManager, but i can't find the ThemeAttribute i have to change if i want to move them away from bottom right. I tried the "SetMenuTopLeft" function in roDialogMessage, but it didn't work.

Thanks
0 Kudos
RokuJoel
Binge Watcher

Re: Help for begginer

if your message is that the screen has been closed, calling another screen.close() isn't much use. When your screen is closed, you normally want to return from the function, and you usually need to return a value, even if you aren't using the value.

- Joel
0 Kudos
DLC
Visitor

Re: Help for begginer

Thanks, it is working, but only on the main page, the one i added, not when i navigate through the menus. What i don't understand is that without my main page, it works. I didn't change the code, just added a button.

Edit: I have tried a few things and i have discovered that the up arrow button is still working. I deleted the lines :

if type(msg) = "roPosterScreenEvent"
if (msg.isScreenClosed()) then
return
end if


in my main to let the control of the buttons to the rest of the code, so the original i haven't modified, but it didn't change anything.
Aren't those two buttons supposed to be coded the same way?
0 Kudos
RokuJoel
Binge Watcher

Re: Help for begginer

you usually need to return a value.

- Joel
0 Kudos
RokuJoel
Binge Watcher

Re: Help for begginer

By the way, if you want detailed answers, you need to post a bit more detailed code, if you want to keep some secrets, just remove or rename anything that is specific to your channel.

- Joel
0 Kudos
DLC
Visitor

Re: Help for begginer

sub Main()
' create and display a roPosterScreen as a backdrop
screen = CreateObject("roPosterScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.Show()

' create our roMessageDialog
dialog = CreateObject("roMessageDialog")
' give the dialog the same message port as the poster screen so we can get events from both
dialog.SetMessagePort(port)

' set the text of the dialog
dialog.SetTitle("Application test")
dialog.SetText("This application is just a test to make buttons and the back arrow work. The layout has not been set yet.")
' add some buttons
' assign them different indexes so we can tell them apart
' when we handle their respective isButtonPressed() events
dialog.AddButton(1, "Channel Guide")
dialog.AddButton(2, "Exit")
dialog.SetMenuTopLeft(true)
dialog.EnableOverlay(true)

' display the dialog
dialog.Show()

' event loop
while true
msg = wait(0, port) ' wait for an event

' make sure the message we got is of the type we are expecting

if type(msg) = "roMessageDialogEvent"
if(msg.isButtonPressed()) then
buttonIndex = msg.GetIndex()
if(buttonIndex = 1)
Second()
else if(buttonIndex = 2)
print "Exit application"
return
end if
dialog.Close()
end if
end if
end while
end sub


Sorry, as i just added two buttons to the SDK example i thought i didn't need to post a lot of code. This is my new main page. The function Second() that i call when i click on the button is the Main() function of the videoplayer example from the SDK i have renamed. I didn't change the rest of the code.
I have removed the isScreenClosed() event because it is defined in the appPosterScreen.brs, so i wanted to see if i was not creating a conflict between the two files, but it didn't change the problem, only the up arrow is working.
As for the return value, i had a compiling error if i used "return -1' that told me i couldn't return a value in a void function.
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Help for begginer

The BACK button will sometimes not work right if you leave a dialog open beneath the top screen. You should close your dialog before opening your second screen.
0 Kudos
DLC
Visitor

Re: Help for begginer

Working perfectly now, a big thank to you Chris (and to you too Joel of course 😄 )
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.