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

2016/2/4

Pause method call

Collin Collin

2016/2/4

#
Hi! I have a scenario in which I want only one method to stop for about 5 seconds while all other methods continue and the scenario keeps running. Is that possible?? Thanks!
danpost danpost

2016/2/5

#
Add an int field to count down the delay time; set it to something in the range of 250 to 300 when some condition to begin skipping the method becomes true. Then you would have:
// instance counter field
private int methodDelayTimer;

// starting delay
if (< condition to start skipping method >) methodDelayTimer = 300;

// calling the method
if (methodDelayTimer == 0) methodName(); else methodDelayTimer--;
Collin Collin

2016/2/5

#
Wow, that looks great, THANKS!!
You need to login to post a reply.