1 Reply Latest reply on Oct 2, 2006 3:05 PM by Rothrock

    using delay, and a while loop... errors.

      i am making a breakout style game, and want to have the score count up +1 for every 1/4 of a second (or 250 miliseconds).
      The problem is, when I use a while loop, I get the error saying "something is slowing flash down, would you like to abort?". I assuming all the cpu is being gobbled up by the while loop, but what otehr alternative is there?

      Here is what I have so far:

      while (true) {
      setInterval(loadNext, 250);{_root.pointage += 1;}

      where "pointage" is the integer where points are stored.
        • 1. Re: using delay, and a while loop... errors.
          Rothrock Level 5
          Wow. That is sooooo wrong in soooo many ways! :)

          Okay, maybe not that wrong and not soooo many ways, but it really isn't what you want to do. You should never use while or for loops to do anything that you want distributed over time. That isn't what they are for and you will get the dreaded "slow script" message.

          The point of setInterval is that it does something at the interval you set. So if you do:

          function upScore(){
          } else {


          That will add one point to the total (assuming you have defined pointage to be some numeric value elsewhere before this all starts) approximately every 250 milliseconds.

          Also, while(true) seems very odd to me. The while() expression is supposed to keep going as long as what is between the parens is true. So normally it would look something like while(someVar>8) or some such. That has the chance of being either false or true. But while (true) is pretty much always going to be true. (Except maybe on opposite day, but I haven't had one of those since highschool!)

          So I've added a part of the upScore routine that checks to see if the inPlay variable is true and if it is it will up the score and if it isn't it will stop the accumulation of score. The inPlay is would be a boolean variable that is set by whatever routine you are using to see if the ball has been missed or not.

          I assume that is what you were trying to do – more or less.