Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    46
    Thanks
    5
    Thanked 1 Time in 1 Post

    Pausing while a function works ...

    I've written a RollDice() function that animates the rolling of dice. The function uses setTimeout to call itself a number of times. A variable DiceRolling is true when the routine is running, and once complete, DiceRolling is set false.

    I have other automated routines that need to run after the routine is completed.

    What is the best way to "pause" my script until the RollDice routine has completed?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,471
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Quote Originally Posted by SlowCoder View Post
    I've written a RollDice() function that animates the rolling of dice. The function uses setTimeout to call itself a number of times. A variable DiceRolling is true when the routine is running, and once complete, DiceRolling is set false.

    I have other automated routines that need to run after the routine is completed.

    What is the best way to "pause" my script until the RollDice routine has completed?
    Split it into two scripts at the point where you want it to pause. Call the second script when the pause period is over.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Or, if it makes sense in the logic of the overall program, RIGHT AFTER you set the DiceRolling flag back to false call the continuation code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •