1 Reply Latest reply on Apr 10, 2011 5:24 AM by ponyodev

    Not A Number Loop problem

    ponyodev

      Hi,
      I have an array and a number to count (dont ask me to do a for loop,  because it is already a loop in the fact that it calls a function that  calls it!) to count and post text to the screen, but its not increasing.  It starts on Up(good) and then freezes, i created an output of the  number and i get first "Undefined" then "NaN" freezes at the bottom. Can  anyone help me?
      Thanks,
      Connah
      PS.Code Here:

      stop();
      
      var score=0;
      dave2.text = score;
      
      
      
      function updateScore() {
          dave2.text = ++score;
          con.text=numtodo;
      }
      function reset() {
          var finalscore=dave2.text
          gotoAndPlay(1);
          score=0;
          finalscore=0;
          dave2.text = score;
          
          
      }
      function dotap() {
          var numtodo=1;
          thechase = new Array();
          thechase[1] = 1;
          thechase[2] = 3;
          thechase[3] = 2;
          thechase[4] = 4;
          var mySetting = 4;
          var myTemp=0;
          var totap = 0;
          totap = thechase[numtodo];
          var waittime = 1
          if (totap==1){
              dick2.text = "up";
              timerup = setInterval(checkup, 1000);
          }
          if (totap==2){
              dick2.text = "down";
              timerdown = setInterval(checkdown, 1000);
          }
          if (totap==3){
              dick2.text = "left";
              timerleft = setInterval(checkleft, 1000);
          }
          if (totap==4){
              dick2.text = "right";
              timerright = setInterval(checkright, 1000);
          }
          myTemp = totap;
      }
      function checkright() {
          if (Key.isDown(39)) {
              if(!Key.isDown(38)){
                          if(!Key.isDown(40)){
                                         if(!Key.isDown(37)){
                                             clearInterval(timerright);
               updateScore();
               numtodo=numtodo+1;
               dotap();
                             }}}
          } 
          if(!Key.isDown(39)){
              clearInterval(timerright);
              reset();
      }
      }
      function checkleft() {
          if (Key.isDown(37)) {
              if(!Key.isDown(38)){
                          if(!Key.isDown(40)){
                                         if(!Key.isDown(39)){
                                           clearInterval(timerleft);
               updateScore();
                numtodo=numtodo+1;
               dotap();
                             }}}
          } 
          if(!Key.isDown(37)){
              clearInterval(timerleft);
              reset();
      }
      }
      function checkup() {
          if (Key.isDown(38)) {
              if(!Key.isDown(40)){
                          if(!Key.isDown(37)){
                                         if(!Key.isDown(39)){
                                           clearInterval(timerup);  
                                           
               updateScore();
                numtodo=numtodo+1;
               dotap();
                             }}}
          } 
          if(!Key.isDown(38)){
              clearInterval(timerup);
              reset();
      }
      }
      function checkdown() {
          if (Key.isDown(40)) {
              if(!Key.isDown(38)){
                          if(!Key.isDown(37)){
                                         if(!Key.isDown(39)){
               clearInterval(timerdown);                     
               updateScore();
                numtodo=numtodo+1;
               dotap();
                             }}}
          } 
          if(!Key.isDown(40)){
              clearInterval(timerdown);            
              reset();
      }
      }
      
      dotap();
      
      
        • 1. Re: Not A Number Loop problem
          Ned Murphy Adobe Community Professional & MVP

          For whatever it is you are trying to develop, you are going to have to learn how to use the trace function to your advantage.  I's main purpose is to help solve problems by presenting the status of things.  You use it to see if a value of something is what you expect it to be.  For the code you show, I can guarantee that at least one value will not be...

           

          You declare the numtodo value in the dotap function

           

          function dotap() {
              var numtodo=1;
          ...

          }

           

          That gives it scope only within that function, it is inaccessible to anything outside that function.

           

          But in all your checking functions you have...

           

          numtodo=numtodo+1;

           

          Those functions cannot access numtodo.