Results 1 to 2 of 2
  1. #1
    saywhatyousee is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Default 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:

    Java Code:
    //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.isHittingWall()){
           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: player class
    Last edited by saywhatyousee; 12-17-2013 at 01:48 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default Re: Executing user typed code

    For better help sooner, it's a good idea to create an SSCCE that demonstrates the problem in a way that we can copy and paste without going to external sites.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Problem stopping a executing JMS code
    By Dark-Redd in forum Advanced Java
    Replies: 0
    Last Post: 10-10-2011, 04:07 PM
  2. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  3. Help required in executing the following code
    By vivekdarshan in forum Advanced Java
    Replies: 6
    Last Post: 01-24-2011, 12:24 PM
  4. Help required in executing the following code
    By vivekdarshan in forum Advanced Java
    Replies: 0
    Last Post: 01-23-2011, 09:34 AM
  5. Executing Ant code pragramatically
    By MikeO in forum Advanced Java
    Replies: 0
    Last Post: 07-24-2007, 09:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •