JavaScript rescurvisiness makes locals globals?

C++, C#, Java, PHP, ect...
Post Reply
Sim
Posts: 412
Joined: Sat Dec 26, 2009 5:37 pm

JavaScript rescurvisiness makes locals globals?

Post by Sim »

I would tag the guy with the recursive signature but forgot his username =}


Some code has been cut out that is unrelated.

Here's a few functions
So it always starts with isValidMove where to is correct such as to.x = 5, to.y=4
it will then enter isInCheck and to values come out t.x=-1 and to.y=-1 to enter pawnMoveCheck

So... ideas?

Code: Select all

 

//to will start out as to.x = 5, to.y=4 or some other #'s that are always correct
    this.isValidMove = function(board, from, to, check)
    {

        if(check == true)
        {
            console.debug("here");
            var boom = this.isInCheck(board, from); //COMES OUT OF HERE different
            if(boom != false)
            {
                alert(boom);
            }
        }
     
        //var pieceMoving = board[from.x][from.y].getPiece();
        var pieceMoving = piece;
        switch(pieceMoving)
        {
            case "p": //pawn
                return this.pawnMoveCheck(board, from, to); //enters here wrong!!
                break;
        }
 
    }
    //checks if king is in check
    this.isInCheck = function(board, spot)
    {

     
        //check all opponents pieces to see if attacking king
        //search for king
        for(y = 0; y < 8; y++)
        {
            for(x = 0; x < 8; x++)
            {
                if(board[x][y] != null && board[x][y] != ".")
                { 
                    //a opponents piece
                    if(board[x][y].getColor() != this.getColor())
                    {
                        //is a pawn
                        if(board[x][y].getPiece() != "p" && board[x][y].getPiece() != "l")
                        {
                            loc = {x: x, y: y};
                            if(this.isValidMove(board, loc, king, false)) // RESURSIVE
                            {
                                return board[x][y].getPiece();
                            }
                        }
                    }
                }
            }
        }
     
        return "no";

    }
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
Post Reply

Return to “Coding”