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?
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.
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.
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?
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.
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.
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.
I have two other beginner questions please :roll: .
1)When you have two .brs files in the source folder, can you use the objects created in one file in the other?
I have a main.brs, with a Main() function that ends like this :
print "my_array"
print my_array
return my_array
Second()
end sub
Then i have a second .brs file, which starts like this :
Sub Second()
print "my_array"
print my_array
On the debugger console, I see :
my_array
1
2
3
4
5
my_array
<UNINITIALIZED>
The Second() function is called, so I think that the “return my_array” of the Main() has been done, but it doesn’t want to print the array. Is there a special way to take an object from another file, or do I have to create all the functions that will use the array in the same .brs file?
Is it possible to return more than one object? For example if I create two arrays in my main(), can i use :
return my_array
return my_second_array
or
return my_array ; my_second_array
(or use a “,” instead of the “;”)
?
Thank you
Edit : I tried to copy the function Second() under my function Main() and deleted the second .brs file, but it wasn’t called this time, as the debugger console stopped after printing “1 2 3 4 5” this time.
So i set it as it was the first time, with two files, and now the Second() function isn’t called anymore
The variable is only available in the scope it was created, so once you left the method it was no longer available. You can pass the variable as a parameter and update it, then the new values will come back, or you can set it up as a function that returns the variable. Another option is to look into the global “m”, but in any programming language you should be careful when using global variables.
If the main function hits a return, it will exit the channel. What you really want is:
sub main()
my_array=[1]
my_array=second(my_array) 'pass my_array to the second function and get the altered array back.
print my_array
stop
end sub
function second(my_array as object) as object
for i=2 to 5
my_array.push(i)
return my_array
end for
end function
you have to explicitly pass the array to the function and explicitly return the array back to the calling function.
It doesn’t matter which .brs file a function is in, they are all treated as if they are in the same file. Sub main is the first subroutine that is called when a channel is launched and when sub main() exits, the channel exits.
Hello,
Guess who has another beginner question :roll:
I have created a SpringBoard like this :
o = CreateObject("roAssociativeArray")
o.Title = title
o.Description = description
o.SDPosterUrl = sdposterurl
o.HDPosterUrl = hdposterurl
o.ReleaseDate = releasedate
My problem is that though I haven’t defined the starRating, I still have the stars on the screen. They are all grey, but still here. Is it possible to remove them or to put them white so that they would become invisible?
“DLC” wrote:
My problem is that though I haven’t defined the starRating, I still have the stars on the screen. They are all grey, but still here. Is it possible to remove them or to put them white so that they would become invisible?
“DLC” wrote:
My problem is that though I haven’t defined the starRating, I still have the stars on the screen. They are all grey, but still here. Is it possible to remove them or to put them white so that they would become invisible?
Use SetStaticRatingEnabled(false). Many of the other fields will just not show if there is no value in them.