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

2021/7/31

Check an input is in a certain range and if not displaying an object

1
2
xixEmilyxix xixEmilyxix

2021/8/1

#
public class beeInput extends Actor
{
    //create variable
    int beeValue;
    boolean error;
    /**
     * Act - do whatever the beeInput wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
      //Create input box, ask for value, set bounds for beeValue
      setImage(new GreenfootImage("Input.png"));
      //set value of bees based off the input
        if(Greenfoot.mouseClicked(this)){
        beeValue = Integer.parseInt(Greenfoot.ask("Please input a value for the amount of bees"));
        if(beeValue < 3 || beeValue > 25)
        {
            World world = getWorld();
            world.addObject(new errorMessagebees(), 400, 400);
        }
        else world.removeObjects(world.getObjects(errorMessagebees.class));
      } 
    }
}
This is what i have now, the error for: else world.removeObjects(world.getObjects(errorMessagebees.class)); is still there, how would i fix that?
danpost danpost

2021/8/1

#
See my provided codes.
xixEmilyxix xixEmilyxix

2021/8/1

#
danpost wrote...
See my provided codes.
I looked and i thought i put it in correctly, did i miss something?
danpost danpost

2021/8/1

#
xixEmilyxix wrote...
I looked and i thought i put it in correctly, did i miss something?
Your line 22 does not match what I finally gave.
xixEmilyxix xixEmilyxix

2021/8/1

#
danpost wrote...
xixEmilyxix wrote...
I looked and i thought i put it in correctly, did i miss something?
Your line 22 does not match what I finally gave.
Thank you, i didnt realise i missed that out
danpost danpost

2021/8/1

#
xixEmilyxix wrote...
Thank you, i didnt realise i missed that out
Understandable, as you quoted before I posted the edit. That is why I mentioned it was edited in my post immediate following the given code.
You need to login to post a reply.
1
2