Sound.PlayAndWait Plays file before text is displayed

GordonH 26 Reputation points
2021-11-07T01:34:28.817+00:00

Hi folks, I have a simple Dice game program written in Small Basic. It can display a number of error messages, and plays an mp3 file for an error condition, or a different mp3 file when a winner is found.
A snippet of code follows. The problem is that while the text display is prior to the Sound.Play in the code, what actually happens is that the sound file is played before the text is displayed on the screen.
How can I fix this ?? Thanks for your help. Gordon H.

If ErrNo = 1 Then
GraphicsWindow.DrawText(x+nl1, y+10, " Must choose dice")
GraphicsWindow.DrawText(x+nl1, y+nl2, " before throwing ")
'....
ElseIf ErrNo = 99 Then
GraphicsWindow.DrawText(x+15, y+10, " This Player Wins")
GraphicsWindow.DrawText(x+10, y+nl2, " ******************")
GraphicsWindow.DrawText(x+nl1, y+nl1+nl2, " Reset All Players")
EndIf
'
ErrSound = FilePath + "\GameSoundErr.mp3"
WinSound = FilePath + "\GameSoundWin.mp3"
If ErrNo < 97 Then
Sound.PlayAndWait(ErrSound)
ElseIf ErrNo = 99 Then
Sound.PlayAndWait(WinSound)
EndIf

Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
277 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GordonH 26 Reputation points
    2021-11-07T06:17:58.003+00:00

    OK, so I fixed this problem myself...
    Changed the main program loop to use a "Game Loop"...
    While ("True"
    ...
    ...
    EndWhile
    In which the texttyped and mouseclick events are set...

    And for some reason, this seems to have fixed the sequence in which events are run

    1 person found this answer helpful.
    0 comments No comments