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).
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??