0

The wait() function



Hi. I have some questions regarding the wait() function in brightscript. The function takes 2 parametres: timeout (ms) and MessagePort. Timeout 0 means wait forever until message is received. The following code is from one of the example scripts, and it is used to check if the video is finished playing: listen: msg = wait(2000,p) if type(msg) = "roVideoEvent" and msg.GetInt() = 8 then sleep(1000) goto start endif goto listen My questions are: - can't you risk, that the video stops playing exactly when the wait-function is timed out and before it returns to listen? - and is there any reason for not using wait(0,p) in this case? - and even if you used wait(0,p), wouldn't you risk missing the right message, if another message is received just before? Best regards Jakob.

1 comment

  • 0
    Avatar
    RokuLyndon


    Yes, you can use 0.

    You would only need to wait (2000,p) if you also wanted to check something else every 2 seconds.

    You can decide what events to listen for. So, if you're not listening for any other events, there's no danger. If multiple events are received at the exact same moment, both events would be logged, and could be processed. Conflicting events has not been a problem, even if there are many different types of events being listened for.
Please sign in to leave a comment.