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

2017/3/21

Timer to switch worlds

TheAngryWarlord TheAngryWarlord

2017/3/21

#
Hello fellows in need to make a timer to switch worlds because I'm not sure how to do it
Super_Hippo Super_Hippo

2017/3/21

#
Create an int field in your world. In the act method, increase the timer by 1 and when it reaches a certain amount, change the world.
TheAngryWarlord TheAngryWarlord

2017/3/23

#
Super_Hippo wrote...
Create an int field in your world. In the act method, increase the timer by 1 and when it reaches a certain amount, change the world.
how?
101929ha 101929ha

2017/3/23

#
Try SimpleTimer (Edit, Import Class, SimpleTimer), set it up and in the world have
public (insert world name here)
{
     super(int, int, int);
     timer.mark();
     if (timer.millisElapsed = (insert time in milliseconds here))
     {
           setWorld(insert other world name here);
     }
}
That should work (I think). EDIT: Sorry, it's meant to be '==' not '='.
danpost danpost

2017/3/23

#
The code given by 101929ha will not work. The timer can only work by way of an act method (lines 5 through 8 will only execute once -- when the timer is marked, or started):
private int timer = 0;

public void act()
{
    timer++;
    if (timer == 1650) Greenfoot.setWorld(new NewWorldClassName());
}
This would be for a 30-second timer in a scenario running at normal speeds -- along Hippo's suggestion.
You need to login to post a reply.