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: 
EnTerr
Roku Guru

Is roMessageDialog.SetFocusedMenuItem() broken

... or is documentation wrong? Doco says
Boolean AddButton(Integer id, String title)
 Adds a button to the screen identified by the title and ID provided. The buttons are at the bottom of the dialog and appear in the order added. When the button is pressed, the script will receive an event from the application indicating the ID of the button pressed.
...
Boolean SetFocusedMenuItem(Integer item)
 Set a button id to highlight. Default is the first button. Return true if successful.

It reads clear - you add buttons by ID, you change focus by ID. But the SimpleInfo example contradicts:
		infomenu.addbutton(1,"button 1")
infomenu.addbutton(2,"button 2")
infomenu.addbutton(4,"exit")
infomenu.setfocusedmenuitem(2) ' 3rd button

By documentation (and seems logical) when you say focus=2, the focus should go to the 2nd button with ID=2 but instead it goes to the 3rd button with ID=4?
0 Kudos
5 REPLIES 5
renojim
Community Streaming Expert

Re: Is roMessageDialog.SetFocusedMenuItem() broken

I'd say the documentation is inaccurate. SetFocusedMenuItem() doesn't really use the same ID used by AddButton(). AddButton() probably creates an array and then SetFocusedMenuItem() is a 0-based index into that array. So even if the first button you add has an ID of 999, you'd use SetFocusedMenuItem(0) to highlight it.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
EnTerr
Roku Guru

Re: Is roMessageDialog.SetFocusedMenuItem() broken

"renojim" wrote:
I'd say the documentation is inaccurate. SetFocusedMenuItem() doesn't really use the same ID used by AddButton(). AddButton() probably creates an array and then SetFocusedMenuItem() is a 0-based index into that array. So even if the first button you add has an ID of 999, you'd use SetFocusedMenuItem(0) to highlight it.

that explains the behavior. but why did they add IDs then? it's not like you can replace an ID or remove by ID. the only use i can think is ArrogantPopup:
dlg = createobject("romessagedialog")
dlg.setText("This dialog will ignore your selection. Do you care?")
dlg.addButton(42, "Yes")
dlg.addButton(42, "No")
dlg.addButton(42, "None of the above")
0 Kudos
TheEndless
Channel Surfer

Re: Is roMessageDialog.SetFocusedMenuItem() broken

The ID is the getIndex() value in the isButtonPressed() message. Allowing you to define IDs has a number of uses, one of those being the ability to have conditionally displayed buttons. Without an ID, you wouldn't be able to always reference Cancel as button 3 if you, for instance, conditionally display Yes/No/Cancel vs. OK/Cancel in a shared dialog.
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
renojim
Community Streaming Expert

Re: Is roMessageDialog.SetFocusedMenuItem() broken

Endless summed it up pretty well. I'd call your example a coding error. I usually give my last button, when it's something like "Close" or "Cancel", an ID of 9. Then if I add or remove a button later in development I don't have to renumber everything and my buttons don't necessarily end up with consecutive IDs. Admittedly it can be a pain when using SetFocusedMenuItem() since there's no way to retrieve the index of a button given its ID, so that part of the code has to be adjusted when a button is added or removed.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
EnTerr
Roku Guru

Re: Is roMessageDialog.SetFocusedMenuItem() broken

"renojim" wrote:
... Admittedly it can be a pain when using SetFocusedMenuItem() since there's no way to retrieve the index of a button given its ID, so that part of the code has to be adjusted when a button is added or removed.

So seems that the implementation of SetFocusedMenuItem() has strayed away from the intent - as documented and as logical from the introduction of IDs.
0 Kudos