Executing user typed code

I am creating a learning aid in the scenario of a game which allows the users to type their own code into a JTextArea for it to be compiled and executed to traverse the player through the level.
Within the learning aid currently, I want to allow the user to use conditional statements and loops so that they can detect if the player has hit a wall while it was moving. An example code of this would look like this:


//The numbers passed into the methods are the number of tiles to move in that direction.
player.moveUp(2);
player.moveLeft(4);
while(player.isMoving()){
   if(player.isColliding()){
       player.moveRight(3);
   }
}

However, when I test this code out, the while() loop and the if statement returns true, but the player.moveRight(3); within the if statement does not get executed.

Within the player class what I am currently doing is storing the player’s movements into an array and assigning target x and y coordinates for the player to move towards. The player will move in the direction specified for the amount passed in within the parameter. Once the player has reached the target distance, it will then move in the second direction that the user might have specified, until it has emptied the array containing the move directions.

I tried emptying the move direction array when the player has hit the wall, but that did not work either.

Here is the player class: http://www.java-gaming.org/?action=pastebin&id=777

 private boolean isMoving = false;
    
    public boolean isPlayerMoving(){
        return isMoving;
    }

isMoving never changes from false thus never hits the inside of loop

That and I see nowhere the following bit of code being ran:

   public void updatePosition(){

       double targetX = playerMapPosision[0];
       double targetY = playerMapPosision[1];

       if(targetX > 0 && targetY > 0 && !commandsHopper.isEmpty() && pause == false){

           isMoving = true;
           
            if(y > targetY) {
                
                moveCharacter(x, y - moveSpeed);

            }else if(y < targetY) {

                 moveCharacter(x, y + moveSpeed);

            }else if(x > targetX) {

                 moveCharacter(x - moveSpeed, y);

            }else if(x < targetX) {
                 moveCharacter(x + moveSpeed, y); 
            }

            if(y <= targetY && y >= targetY && x >= targetX && x <= targetX && playerReachedEnd == false || isColliding == true){
                commandsHopper.remove(0);
                getNextTarget();
            }
       }else{
            isMoving = false;
       }

    }

EDIT: Added second block of code, never see that method called.

Also, just woke up… heh

Updateposition(); is getting called in the update() method underneath it. The update(); method itself is being called in the main game loop so it is getting called numerous times a second.

Also, is moving is set to true within the updateposition(); method once an initial target x, and y coordinates have been set. This is checked by the first if statement in that method. Also even if I add isMoving = true; within all the move methods, the if statement within the while loop from my example code on the top post does not execute the player.moveRight(); method.

Thanks for the reply.

Does it even reach that if?

Ah sorry for that. I just typed the example as an example, I was not using the actual method names which I have in the player class. I use isColliding(); to detect if the player has hit the wall.

The isColliding variable is set to true within the player class’s parent class. It checks if the bounding box is colliding with the background and sets isColliding to true when it does. I then return isColliding within the isColliding(); method to allow the player to detect if the player is colliding with the wall.