If you set the [b]sound[/b] to true, it will play the sound continuously.
You need to set the [b]sound[/b] to off if you do not want to play it.
There are many way to do it.
For example: if you want the sound to play for 0.5 second.
Define a varrable [b]t_on[/b] to remember when the time is on.
add t_on=t; just after you set sound=true;
And add the following code to constraint page:
If (Math.abs(t-t_on)>0.5)sound=false; // turn the sound off when it has been play for 0.5s.
You need to tell the program/computer what you want to do.
The program/computer can not decide it for you!