Simple recursive question

Bonjour :slight_smile: Been a long time, but I havent done much flash lately. I have a question that I know is probably retarded, because when we have small problems like these, the answers are usually short. Anyways, making a simple minesweeper game and I’ve got the basics down. Whenever you click on a square that has 0 mines around it though, every square around it should be clicked, and if one of those has 0, the squares around it should be clicked too right? Well, that involves a recursive function, which should be easy, but for some reason… isnt.

This function is called when a non-mine is clicked. What is does is check all the mines surrounding the one clicked and then it counts the amount of mines there. If there are 0 mines, however, it must recurse and count the mines of the squares surrounding it. Problem is, this only gets called one time, not 8 like it should be…

function checkMines(object) {
    x = object._x/20;
    y = object._y/20;
    nummines = 0;
    // Check all the areas around it for mines
    for (i=-1; i<2; i++) {
        for (j=-1; j<2; j++) {
            if (_root["square_"+(x+i)+"_"+(y+j)].mine) {
                nummines++;
            }
        }
    }
    // Set the square as clicked and put the number in the square, otherwise assume 0 and click around it.
    object.gotoAndStop(3);
    if (nummines == 0) {

// This is the part right here, its only running one time rather than 8

        for (i = -1; i < 2; i++) {
            for (j = -1; j < 2; j++) {
                trace("x="+x+"; y="+y+"; i="+i+"; j="+j+";");
                if (!((j == 0) && (i == 0))) {
                    if ((x + i >= 0) && (y + j >= 0))
                        _root.checkMines(_root["square_"+(x+i)+"_"+(y+j)]);
                }
            }
        }

// End irritating part :)

    } else
        object.number.text = nummines;
}

Now if you look in there, there’s a trace statement that should be printed like 9 times… it only gets traced once, so by calling _root.checkMines again, it cancels them all out for some reason! With the above code and clicking on a mine with nothing surrounding it, I get the following:

x=8; y=11; i=-1; j=-1;

That’s good for a first line. It’s the 9th square over (x=8) and the 12th down (y=11), and the recursion is starting at -1, -1… so what the hell? The square to the top left is being clicked, but it just stops there. Shouldn’t it return to the inital recursion and continue it?

Testing again without the actual call to checkMines returns:

x=2; y=1; i=-1; j=-1;
x=2; y=1; i=-1; j=0;
x=2; y=1; i=-1; j=1;
x=2; y=1; i=0; j=-1;
x=2; y=1; i=0; j=0;
x=2; y=1; i=0; j=1;
x=2; y=1; i=1; j=-1;
x=2; y=1; i=1; j=0;
x=2; y=1; i=1; j=1;

So, my question is: what the hell? Do I need a certain return value of the function checkMines to continue the recursion or what?