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

2012/11/15

HELP!

USER67 USER67

2012/11/15

#
Anyone know how to add a limit to a counter that displays a success message when reached OR a time limit counting down from a specified time that when reached displays a "time out" message?
Gevater_Tod4711 Gevater_Tod4711

2012/11/15

#
A limit to a counter is easy:
int counter; //the counter you are using;
int counterLimit; //the limit of the counter;

public void act() {
    if (counter >= counterLimit) {
        //the winner message;
        //or whatever you want in this case;
    }
}
A time limit is a bit more dificult. You should know how many acts are there per second to know exactly how much time you have got. this scenario could help you find out how many time is ther per act. If you know this (you could also just estimate how many acts):
//in the act mehtod;
if (counter < counterMax) {//counter counts up every act and counterMax is the number of acts you want for the time;
    counter++;
}
else {
    //time up;
}
USER67 USER67

2012/11/21

#
That's brilliant mate!!! thanks for your help!
USER67 USER67

2012/11/28

#
Hi mate, public void act() { if (Counter == Counterlimit){ ***************************** } } got this far with the limit, what do i put in the star gap for the game to stop/end?
danpost danpost

2012/11/28

#
Greenfoot.stop();
return;
USER67 USER67

2012/11/29

#
Thanks a bunch!
You need to login to post a reply.