8 Replies Latest reply on Jul 21, 2006 6:23 AM by Darth Crap

    256 Levels Or Recursion?

    Darth Crap
      I am creating a maze game which uses a random maze generator which has the attached code in it

      Unfortunately,this generates the following error
      quote:

      256 levels of recursion were exceeded in one action list.


      I have measured the program (i originally made it in javascript, in which it works), and it can reach upto 1100 levels of recursion.

      Is there anyway of bypassing the error?

      Thanks


        • 1. Re: 256 Levels Or Recursion?
          Jim_Esteban Level 1
          What's W?
          • 2. Re: 256 Levels Or Recursion?
            Darth Crap Level 1
            a.) W is width, H is height, S is the size of the blocks which are drawn.
            b.) all i need to know is how to bypass the error. It is used to draw mazes with sizes anywhere from 27 to 123. It's when you get pass the 40 stage when the error starts occuring.
            • 4. Re: 256 Levels Or Recursion?
              Rothrock Level 5
              I believe there once was a way to open up a compile SWF and replace some bytes to increase the recursion levels – maybe, or I could just be confused about the delay before the "slow script" message was shown.

              But for some reason I think that went away with recent versions of Flash. Or maybe not. I just don't know.

              But the best solution would be to rewrite the function. I'm not sure I can really give any advice on that end of it – I don't really understand what that code is doing, but that will probably be the best approach.
              • 5. Re: 256 Levels Or Recursion?
                blemmo Level 1
                Try to rewrite that code without recursion. Does every ClearPoint() action have to have its own while() loop? Maybe one is enough, so you could have another function doing the loop and call ClearPoint() in that, something like that:

                function DoClearPoint(myarrGrid,x,y) {
                intCount = ValidCount(arrGrid, x, y);

                while (intCount > 0) {
                switch(Math.round(Math.random() * 1234) % 4) {
                case 0:
                if (ValidMove(arrGrid,x,y-2) > 0) {
                arrGrid[(y-1)*W+x] = 1;
                ClearPoint(arrGrid,x,y-2);
                }
                break;
                case 1:
                if (ValidMove(arrGrid,x+2,y) > 0) {
                arrGrid[(y*W)+x+1] = 1;
                ClearPoint(arrGrid,x+2,y);
                }
                break;
                case 2:
                if (ValidMove(arrGrid,x,y+2) > 0) {
                arrGrid[(y+1)*W+x] = 1;
                ClearPoint(arrGrid,x,y+2);
                }
                break;
                case 3:
                if (ValidMove(arrGrid,x-2,y) > 0) {
                arrGrid[(y*W)+x-1] = 1;
                ClearPoint(arrGrid,x-2,y);
                }
                break;
                default:
                break;
                }
                intCount = ValidCount(arrGrid, x, y)
                }
                }

                function ClearPoint(myarrGrid,x,y){
                // code without recursive calls
                }

                You would start the process with DoClearPoint() and handle the calls to ClearPoint() in that. This way you won't see the recursion level warning because there is no recursion.

                hth,
                blemmo
                • 6. Re: 256 Levels Or Recursion?
                  jelaplan Level 1
                  You can increase the recursion levels with a tool named SWF ScriptLimits Injector. This is a simple command line tool that also supportes increasing the timeout period from the default 15 seconds.
                  http://www.buraks.com/swfsli/

                  That said, I think that if you have so many levels of recursion, you should probably think about other ways to factor your code.

                  • 7. 256 Levels Or Recursion?
                    Darth Crap Level 1
                    blemmo - If i understood you correctly, then i think your method won't work. The Random Maze Generator uses this function, so it clears a random maze block, then calls itself again from that maze block to clear another one, untill a full maze is made.

                    jelaplan - I Will try this.

                    Oh and by the way, here is the actual full code for frame 4 (the other frames just are loading a 'variable setting' frames) incase it helps.

                    • 8. Re: 256 Levels Or Recursion?
                      Darth Crap Level 1
                      SOLVED
                      SWF ScriptLimits Injector did the trick

                      Thanks