This site requires JavaScript, please enable it in your browser!
Greenfoot back
bangtan
bangtan wrote ...

2021/5/26

input text box

bangtan bangtan

2021/5/26

#
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.
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());
        }
    }
danpost danpost

2021/5/26

#
You could inserting the following at line 28:
answer = 0;
You need to login to post a reply.