i have successfully made to ask the player to input a value. i asked the player to input the answer on the problem given on the game and i assigned a certain value for the correct answer. i tried to answer to see if the program is working and inserted a wrong value, then the try again world appeared. i tried to reset the whole game but when it comes to the ask part, the "try again" automatically appears. how can i reset the input value?
Here is my program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public double answer; public double correctans = 57.24 ; public void act() { ask(); check(); } public void ask() { if (Greenfoot.isKeyDown( "enter" )) { String input = Greenfoot.ask( "On which point should the car turn? Round of to 2 decimal places" ); answer = Integer.valueOf(input); } } public void check() { if (answer == correctans) { Greenfoot.setWorld( new congrats()); } if (answer != correctans) { Greenfoot.setWorld( new retry()); } } |