issues with buttons on regScreen

The regScreen example for some reason shows to add buttons but i cant get them to do anything.

here is some code i tried…

Function displayRegistrationScreen() As Object

    regsite   = "go to " + m.UrlWebsite
  ' regscreen.SetMessagePort(CreateObject("roMessagePort"))

    port = CreateObject("roMessagePort")
    regscreen = CreateObject("roCodeRegistrationScreen")
    regscreen.SetMessagePort(port)

    regscreen.SetTitle("")
    regscreen.AddParagraph("Please link your Roku player to your account by visiting")
    regscreen.AddFocalText(" ", "spacing-dense")
    regscreen.AddFocalText("From your computer,", "")
    regscreen.AddFocalText(regsite, "spacing-dense")
    regscreen.AddFocalText("and enter this code to activate:", "spacing-dense")
    regscreen.SetRegistrationCode("retrieving code...")
    regscreen.AddParagraph("This screen will automatically update as soon as your activation completes")

    regscreen.AddButton(1, "Get a new code")
    regscreen.AddButton(2, "Back")
    regscreen.Show()

'return regscreen 

while true
msg = wait(0, regscreen.GetMessagePort())
      if msg.isButtonPressed() then
                if msg.GetIndex() = 1

print "new code pushed"
return regscreen 
exit while
                endif
                if msg.GetIndex() = 2

print "exit pushed"
exit while
                end if
  endif

end while

regscreen.Close()

End Function

it seems the issue is once “return regscreen” gets called it makes the buttons useless, you can click them but they wont do anything.

and of course until you click on the “get a new code” button it will just sit at “retrieving code…

If I understand your code correctly, I’m guessing it has something to do with your call of displayRegistrationScreen().

You should have that “return regscreen” after the regscreen.show(). Then right after that, there should be an end function.

Then in your calling code, you should have regscreen = displayRegistrationScreen() before your while loop.

Also, I think that shouldn’t be a wait 0, you should have it check the site every so often to see if the code has been entered there.

I’m not quite seeing how you are getting the reg code… but try something like this…


sub main()
   http = createobject("rourltransfer")
   http.seturl("http://www.somesite.com/testcode.cgi?code=" + code)
   regscreen = displayRegistrationScreen()
   registered = 0
   while true
      msg = wait(1000, regscreen.GetMessagePort())
         if msg.isButtonPressed() then
            if msg.GetIndex() = 1
               regscreen.close()
               http.seturl("http://www.somesite.com/testcode.cgi?code=" + code)
               regscreen = displayRegistrationScreen()
            else if msg.GetIndex() = 2
               exit while
            end if
         else
            if http.gettostring() = "true" then
               registered = 1
               exit while
            end if
        end if
   end while
   regscreen.close()
   if registered = 1 then
      ' do something...
   end if
end sub

thanks but i am using the register example, th eonly thing i changed was adding the buttons to do something because the they are shown how to add them in the example.

but they aren’t coded to actually do anything

I will look this over in more detail what you posted to see if its something that will work, but at first glance i am not sure it will withe the way the register example is set up.

and again i really appreciate your time to look this over and add your solution, i will look it over a lot more in the morning :grinning_face_with_smiling_eyes:

I left out the code for the displayRegistrationScreen() function… but I am suggesting having it there… just have your loop outside. :slightly_smiling_face:

I do not want to change any of the example that the docs have in the register example, i just want to use the buttons that they show. There has to be a way to add functionality to those buttons in that example without rewriting any code.

i thank you for your help, but i just want to get this working without any rewriting of the functions if possible. this should be a simple thing and not sure why it was excluded in the docs :?

If i cant get some help on this maybe will have to consider changing it more similar to what you showing here but i do not use the same method as you do , with calling a cgi file etc… i use the register example exactly as is cause except for the buttons it works great

What SDK example are you using, because neither the 2.7 nor 2.6 examples look like yours? It looks like you tried to combine the displayRegistrationScreen() and doRegistration() functions, which is where your problem is occurring. The msg.isButtonPressed() part of the wait loop responds to the button presses, so the code is there, and gets called correctly in the stock sample.

ok yes i see what you mean now endless…

i went back to using the the version from 2.7, i was just trying to get some functionality from those buttons

i get the code etc on the screen… but it is still not doing anything once i am here and i have to hit the home key to get out.

what is missing to make these buttons actually work and not just beep?

Based on the original code you posted, the problem could be at least partly due to returning from the function before closing the screen. When you return prematurely like that, you could be left with an open screen, but no event loop to handle your button presses.

chris, i went back to using the example exactly as is.

so how do i get the buttons work with the register example in the 2.7 sdk? all they are doing now is beeping and doing nothing i cant go up to get out either

To start, you need to add logic to your event loop to handle your new buttons. It looks like you started to do that at one point. Something along the lines of…

if msg.GetIndex() = 0
  regscreen.SetRegistrationCode("retrieving code...")
  getNewCode = true
  exit while
else if msg.GetIndex() = 1
  ' do something
else if msg.GetIndex() = 2
  ' do something else
endif

chris this is where it is confusing to me…

if you look at the register example in the 2.7 sdk

you will see this code is already there. in the doRegistration() above, in the first Function of the regScreen.brs file.

again i have went back and used the register example as is, are you telling me i need to add this code elsewhere?

and if so will that effect that same code placed in the doRegistration()

displayRegistrationScreen() is where you actually see the buttons added, so do i add it there?

Its confusing why the example wasn’t made a actual working example, makes using the examples so confusing at times :?

i understand the backend not working but why the button functionality was left out is curious to me.

I’m sorry, I’m not sure I follow you. The event loop already exists in the sample code. You just have to add handling for your new buttons to that event loop. Don’t add a completely new event loop.

The examples are only examples. They must be adapted to specific situations since no two content providers are going to implement the back end the same way. The examples are to learn from and build on, they are not a complete a solution to every developers situation.

“RokuChris” wrote:
The examples are only examples. They must be adapted to specific situations since no two content providers are going to implement the back end the same way.. The examples are to learn from and build on, they are not a complete a solution to every developers situation

As i already said Chris i understand that with the backend but why not have the buttons work?

the up button or exit buttons dont do anything. when the examples are all we have to learn from and no other forums but this one to ask questions about brightscript. It makes learning quite difficult :? what nay be simple to you, is not for everyone else.

I have posted code to show i am trying to figure this out and not just asking for you to write my channel. every way i have tried for the last two days fails.

I would appreciate if someone could help on this and i am sorry if i have offended anyone. But i need help so i came to the “help” forum.

“dynamitemedia” wrote:
the up button or exit buttons dont do anything.

I just installed the 2.7 SDK “register” example and it seems to work as expected. The UP and BACK remote keys do not raise an isScreenClosed() event on a roCodeRegistrationScreen. I believe that has always been the case. The best way to give the user the ability to back out of a roCodeRegistrationScreen is to add a “Back” button like the one in the example.

The best way to give the user the ability to back out of a roCodeRegistrationScreen is to add a “Back” button like the one in the example.
I said i have used the example exactly “as is” in my other posts and that the back button is there but i can’t get the " back" button to do anything.

i can’t get the “get new code” button to do anything either. even if you put a print statement, nothing prints to the debugger when i click these buttons.

i have shown examples of me trying to get them to work, they dont work as is. and even when i tried as shown by my code above, to get them to work they do not work. I don’t know what else or any other way to ask.

can you tell me from this example if you loaded it, why these buttons don’t work and what needs to be done to get them to work?

thank you

When you say you have used the example as is, do you mean you have installed the example channel or that you have copied code out of the example channel and into your channel? The “Back” and “Get new code” buttons work correctly for me when I install the example channel. If you are just copying code from one channel to another, there is probably going to be some tweaking necessary. A few of us have tried to point you in the right direction, but exactly how the example will need to be tweaked to fit into some other channel is not easy to predict.

When you say you have used the example as is, do you mean you have installed the example channel or that you have copied code out of the example channel and into your channel?

I am using the “register example” from the examples in 2.7 SDK. I have said this several times. and in fact have counted 7 x’s in this thread where i said i am using the “register example” and as is, is just that as is.. i showed that i tried changing it to get the buttons to work, not sure why or what i said that made anyone think otherwise.

its not in my code, not in another channel, i am trying to use the “register example” to learn how to use it so i can add to my channel later.

The “Back” and “Get new code” buttons work correctly for me when I install the example channel.

when i click on the buttons they do nothing. the only thing i changed was added a sleep(5000) because it was registering so darn fast i couldn’t test the buttons. so the sleep makes it sit there “retrieving code…” for 5 seconds

If adding the sleep made the buttons not work, maybe you can tell me what i can do so that this example just doesnt fly through and go to the congratulations screen in about 1 second flat.

i have print statements and they too are doing nothing as well. are you saying the buttons you see on the screen are working for you when you click them? the “get a new code” and “Back” buttons?

A few of us have tried to point you in the right direction, but exactly how the example will need to be tweaked to fit into some other channel is not easy to predict.

I am not asking about tweaking it, i have stated from the get go, i just want to know how to get the “register Example” and its buttons to work. I only want to know how to get this example working, then i can learn what its doing so i can use it and tweak into my channels. I am not asking anyone show me anything other than how to make these buttons work.

“dynamitemedia” wrote:
when i click on the buttons they do nothing. the only thing i changed was added a sleep(5000) because it was registering so darn fast i couldn’t test the buttons. so the sleep makes it sit there “retrieving code…” for 5 seconds

If adding the sleep made the buttons not work, maybe you can tell me what i can do so that this example just doesnt fly through and go to the congratulations screen in about 1 second flat.
Adding a sleep is probably exactly what’s causing it to not work for you. Sleep pauses all code execution for the duration specified, so no events would get through either.
Commenting out the “if msg = invalid exit while” line should get it to not exit immediately for you.

Everyone posting in this thread is trying to help you. It’s understandably frustrating for you, but if you’re going to have an attitude every time one of us asks a question, you’re going to quickly run out of people willing to help. Clearly adding a line of code to the example is not using it “as is” as you keep repeating, and in fact is what’s preventing it from working for you, so if you’re not going to provide the full details, and you’re going to get upset every time someone asks for more details, then you’re not going to get very far.

i was using as is and it was not working for me. so i added the sleep to it.

if you look at the code i posted earlier, does it show a sleep? no it does not because i am trying everything i can to get it to work, the example does not seem to work for me. all i have asked is someone tell me how to get it to work.

it still does not work as is…

also what you posted :

Commenting out the “if msg = invalid exit while” line should get it to not exit immediately for you.

can you explain why this would stop it from registering so quickly and going straight to the “congratulations” screen?

I tried it, and this also doesn’t do anything to stop it from jumping right on through the to the congratulations screen.

“dynamitemedia” wrote:
i was using as is and it was not working for me. so i added the sleep to it.

if you look at the code i posted earlier, does it show a sleep? no it does not because i am trying everything i can to get it to work, the example does not seem to work for me. all i have asked is someone tell me how to get it to work.
As I noted earlier, the code you posted is not directly from the register example. It’s some sort of combination of two of the functions from that example, and won’t work. Whether it has a sleep or not is irrelevant to your current issue, as it’s clearly not the example code that you’re using “as is”.

“dynamitemedia” wrote:

Commenting out the “if msg = invalid exit while” line should get it to not exit immediately for you.

can you explain why this would stop it from registering so quickly and going straight to the “congratulations” screen?

I tried it, and this also doesn’t do anything to stop it from jumping right on through the to the congratulations screen.
It won’t. I missed the outer While loop. Sorry…
Try temporarily commenting out the “if status < 3 return status” line instead.

EDIT: To expand on that… unless your m.UrlGetRegResult url returns XML with a root node of , status is going to equal 2 and exit the screen, because of these lines in the checkRegistrationStatus() function, which I suspect is why it’s exiting immediately:

if not xml.Parse(rsp) then
    print "Can't parse check registration status response"
    ShowConnectionFailed()
    return 2
endif

if xml.GetName() <> "result" then
    print "unexpected check registration status response: ", xml.GetName()
    ShowConnectionFailed()
    return 2
endif