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

2021/6/8

How to use stop the program

BlueHand BlueHand

2021/6/8

#
Hello! I am trying to make it so that when you press a button (Buttons class with Falsebutton/Truebutton subclasses under it) 5 times, the program stops. How do I do this?
danpost danpost

2021/6/8

#
Add a public static int field to your world to track clicks:
public static int clicks;
Initialize it to zero in the constructor
clicks = 0;
In class of button(s), increment the field when clicked:
MyWorld.clicks++;
In world act method, add the following line:
if (clicks == 5) Greenfoot.stop();
You need to login to post a reply.