[Javascript] causing script to pause before moving to next command

Trey H tutwabee at hotmail.com
Fri May 3 15:57:00 CDT 2002


David,
You might want to use a setTimeout() command to pause the script before it 
does its action.  Play around a little with the amount of milliseconds to 
pause it, because you might need it to be long or short depending on the 
sound.  Here is what the code might look like:

if (player[sy][sx][0] < 100) {
/* Hit something */
/* need to have set timeout here to delay setting image and playing sound */
setImage(sy,sx,103,false);
setTimeout("playSound(0)", 20); /*  Pause for 20 millaseconds */

====================================
Trey: tutwabee at hotmail.com
Get free JavaScripts at the Blue Dragon!
Just go to:
http://www.websiter.biz
====================================
Make money by being online:
http://www.degoo.com/index.php?refid=tutwabee
===================================
Earn free traffic for your website easily:
http://tools.addme.com/servlet/popview?id=52260
====================================



>From: David Merchant <merchant at LATECH.EDU>
>Reply-To: javascript at LaTech.edu
>To: javascript at LaTech.edu
>Subject: [Javascript] causing script to pause before moving to next command
>Date: Fri, 03 May 2002 15:29:08 -0500
>
>I need to have a Javascript pause after a user makes an input before the
>computer makes its move (this is a javascript for Battleship which I'm
>tweaking to add sound effects in). I need the computer to wait a second for
>the sound effect from the player's move to finish before it makes a move
>(that will have a sound effect as well).
>
>I'm doing a brain fart, and can't seem to get it to work, all attempts have
>failed to pause the script.
>
>if (player[sy][sx][0] < 100) {
>/* Hit something */
>/* need to have set timeout here to delay setting image and playing sound 
>*/
>setImage(sy,sx,103,false);
>playSound(0);
>
>
>TTFN,
>David
>
>Systems Librarian, Louisiana Tech University
>merchant at latech.edu
>JavaScript List Administrator (www.mountaindragon.com/javascript/)
>Webmaster, HTML Encyclopedia (www.mountaindragon.com/html/)
>Webmaster, Memorial Day Page (www.usmemorialday.org/)
>Webmaster, Midori Ito Site (www.mountaindragon.com/midori/)






_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




More information about the Javascript mailing list