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

2018/4/28

Help with Greenfoot.ask and Timer

Lee9901 Lee9901

2018/4/28

#
I have a timer on my screen that counts down which works fine. However, when the program does the method Greenfoot.ask(), the timer stops counting down. The timer continues to count down only when the user's input is finally done. I want the timer to continue counting down while the Greenfoot.ask() method is still going. Is there a way to do this? So for example this is what it would look like. public MyWorld() { super(600, 400, 1); addObject(new Timer(), 500, 500); addObject(new UserInput(), 200, 200); } public class Timer extends Actor { private int time = 180; public void act() { setImage(new GreenfootImage("" + time, 20, Color.WHITE, Color.BLACK)); time--; } } public class UserInput extends Actor { public void act() { String input = Greenfoot.ask("......."); } }
danpost danpost

2018/4/28

#
Is the timer to be used a something to limit the amount of time the user has to input what is asked for? What kind of input is being asked for?
Lee9901 Lee9901

2018/4/29

#
Yeah, the timer represents the amount of time the user has before answer is invalid (similar to like the Jeopardy game show) I just didn't put the code in for that yet. The input is asking for the answer to a question so like Greenfoot.ask("Who was the 1st president?") Problem is, the timer doesn't go down when the program executes Greenfoot.ask()
danpost danpost

2018/4/29

#
Lee9901 wrote...
Yeah, the timer represents the amount of time the user has before answer is invalid (similar to like the Jeopardy game show) I just didn't put the code in for that yet. The input is asking for the answer to a question so like Greenfoot.ask("Who was the 1st president?") Problem is, the timer doesn't go down when the program executes Greenfoot.ask()
You will not be able to use Greenfoot.ask to prompt for an answer then. No other code executes when ask is used. You will need another way to gather the input (like creating your own text input code).
Lee9901 Lee9901

2018/4/29

#
*sigh* Thats what i thought. All right thanks for clarifying danpost. I truly appreciate it. :)
You need to login to post a reply.