2 Replies - 729 Views - Last Post: 20 December 2013 - 09:23 AM Rate Topic: -----

#1 saywhatyousee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-December 13

Executing User Code

Posted 17 December 2013 - 05:36 AM

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.

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Executing User Code

#2 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: Executing User Code

Posted 20 December 2013 - 04:13 AM

Have you tried using breakpoints to see what your code does?
That's what I would do. You might see that your program DOES skip the if statement or maybe something else.
Was This Post Helpful? 0
  • +
  • -

#3 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: Executing User Code

Posted 20 December 2013 - 09:23 AM

Would better if you gave us the code for those functions you are calling.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1