if msg.isButtonPressed() error

I keep getting this error

255:     screen.Show()
256: while true
257: msg = wait(0, screen.GetMessagePort())
258:       if msg.isButtonPressed()
259:        ' print "Evt: msg.GetMessage();" idx:"; msg.GetIndex()
260:
261:                 if msg.GetIndex() = 1
262:            exit while
263:                 endif
264:                 if msg.GetIndex() = 2

/tmp/plugin/FPAAAA997H4h/pkg:/source/appMain.brs(258): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.

258:       if msg.isButtonPressed()

sometimes it will still load with it sometimes it wont

Sounds like you are getting invalid instead of an actual message, which was covered somewhat in http://forums.roku.com/viewtopic.php?f=34&t=31487. The simple solution is to throw another check that a valid event message was received (msg <> invalid).

is because there is no “then” in there?

ive had issues with them placed in the wrong spot

msg = wait(0, screen.GetMessagePort())
         if msg.isScreenClosed() then
                print "Screen closed"
                exit while
            else if msg.isButtonPressed() 

or should the "then " be with the elseif msg.isButtonPressed() ?

The “then” of an if statement is optional, so that has no bearing. I was referring to the msg variable holding an invalid values, so something like this may be required:


msg = wait(0, screen.GetMessagePort())
if msg<>invalid then
    if msg.isScreenClosed() then
        print "Screen closed"
        exit while
    else if msg.isButtonPressed() 
        ... do something ...
    end if
end if

We have an open bug we can easily reproduce by hitting the Home button on a script that causes a wait() with a timeout of zero to return an invalid message. We consider this a bug on our part and will fix it.

Do you have another scenario that causes invalid to be returned from a wait() with a timeout of zero??

–Kevin