10-04-2022, 12:10 AM
It's a racing issue. Think how fast the loop travels, several hundreds of times per second. Now multiply that sound call over and over... See what I'm getting at? Sound plays in the background and every time it is called again, before it finishes, that process keeps multiplying to some degree.
Try this...
Run it and note that it immediately exits, but the sound keeps playing a lot longer than 1/10th of a second.
I actually tried what you came across with the _KEYDOWN example, and didn't include it so I wouldn't drive folks crazy. My best guess as to why INKEY$ doesn't work the same way is because it has some built in delay that negates the racing vulnerability we find in the _KEYDOWN statement.
Pete
Try this...
Code: (Select All)
FOR i = 1 TO 4000
SOUND 1000, .1
NEXT
Run it and note that it immediately exits, but the sound keeps playing a lot longer than 1/10th of a second.
I actually tried what you came across with the _KEYDOWN example, and didn't include it so I wouldn't drive folks crazy. My best guess as to why INKEY$ doesn't work the same way is because it has some built in delay that negates the racing vulnerability we find in the _KEYDOWN statement.
Pete