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

2012/2/26

for loop working on menu

programmer22 programmer22

2012/2/26

#
ok so when you start my game it shows the menu then a bunch of worms is their anyway i can make it so the for loop only works when the game starts?
danpost danpost

2012/2/26

#
To have code execute only at the initial start of the scenario, create a method called 'public void started()' (a method of this name will over-ride the empty super-class method with the same name that is called when the 'Run' button is pressed. The only problem to deal with is, what happens when to scenario is paused and then re-started (it will run again). That being said, you need a boolean instance variable in the world class to track the initial start.
public boolean hasStarted = false;
Then, start your new method with
public void started()
{
    if (hasStarted) return;
    hasStarted = true;
    // The code you want run one time at initial start-up
}
You need to login to post a reply.