question

GordonH-7176 avatar image
0 Votes"
GordonH-7176 asked GordonH-7176 answered

Sound.PlayAndWait Plays file before text is displayed

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

GordonH-7176 avatar image
1 Vote"
GordonH-7176 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.