You do need a field to control the slow motion portion of the code; however, instead of using two fields (a timer and a flag) using one is easier (a timer; if the timer is not zero, decrement it and if it becomes zero, resume normal speed; if the timer is zero, no action required; when a potato is eaten, set timer to maximum slow time and set slow speed).
// with instance field
private int slowTimer;
// in act method
runSlowTimer();
eat();
// with these methods
private void runSlowTimer()
{
if (slowTimer > 0)
{
slowTimer--;
if (slowTimer == 0) Greenfoot.setSpeed(50);
}
}
private void eat()
{
Actor potato = getOneIntersectingObject(Potato.class);
if (potato != null)
{
getWorld().removeObject(potato);
slowTimer = 5000;
Greenfoot.setSpeed(25);
}
}
