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

2013/6/11

The difference betwen greenfoot.stop() and the pause button?

rowanto rowanto

2013/6/11

#
Is there any difference between the greenfoot.stop() method and the pause button in greenfoot? I think it's a totally different thing?
bourne bourne

2013/6/11

#
It has the same effect.
Zamoht Zamoht

2013/6/11

#
Greenfoot.stop() is the exact same thing as clicking on the pause button and if you call the Greenfoot.stop() method the pause button will change into a run button just like it will when you click pause.
danpost danpost

2013/6/11

#
The difference is WHO (or what) stops the scenario. The programmer decides when to stop the scenario when using 'Greenfoot.stop();' within the code; the user decides when to stop the scenario by clicking on the 'Pause' button.
rowanto rowanto

2013/6/11

#
Wow, such quick answers. So that means, if I do greenfoot.stop() in the middle of doing something, then I click the run button, so it's just doing the act method for all actors from the beginning again? So theoretically, there's now no easy way to put a pause in the middle of the methods and then continue it again when the user wants it?
Duta Duta

2013/6/11

#
I'm confused as to what you want to do. If you call Greenfoot.stop(), then the scenario is paused - when the user presses "run", then the scenario will continue from where it left off.
rowanto rowanto

2013/6/11

#
Sorry for being not clear, but taken we have the code public method act() { dosomething(); dosomething(); dosomething(); somePauseMethod(); // which will pause indefinitely until the user do something continueDoingSomething(); continueDoingSomething(); } if I do greenfoot.stop() in the middle, then I click the run button again, the act method will be run from the first line again no? What I want is an ability to pause indefinitely in the middle, and then continue in the middle again.
Zamoht Zamoht

2013/6/11

#
Nope it runs the act method to the end and then stops. There are different ways to implement a pause function. Maybe some of the others can give you an example (Okay not the biggest help but it's late, so maybe I'll help you tomorrow if you're still in trouble there).
danpost danpost

2013/6/11

#
There are two ways to do this, only one of which is the way you want to do it (but, you have not been clear enough for us to determine which way you would need). It really depends on if you want the whole scenario to be 'on hold' while the user does whatever; or just this particular act method. To put everything on hold until the user does something, you could use:
1
2
3
4
5
6
7
8
9
public method act()
{
  dosomething();
  dosomething(;
  dosomething();
  while (/* !(user has done something) */) Greenfoot.delay(1);
  continueDoingSomething();
  continueDoingSomething();
}
To only control what this act method does:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// add instance field
private boolean waitingForUserToDoSomething = false;
// the act method
public void act()
{
  if (!waitingForUserToDoSomething)
  {
    dosomething();
    dosomething();
    dosomething();
    waitingForUserToDoSomething = true;
  }
  if ( /* user has done something */ )
  {
    waitingForUserToDoSomething = false;
    continueDoingSomething();
    continueDoingSomething();
}
rowanto rowanto

2013/6/11

#
The idea is to repaint the whole world, pause, then let the user see the screen. Then if a user thinks he has seen enough, he will click on something (maybe the run button), then everything will continue. The problem is in the "/* !(user has done something) */" part. I guess I will need to make it always check for something. So I guess I'll need a seperate thread of something event based? @.@
rowanto rowanto

2013/6/11

#
and the pause method needs to be in the middle of the act().
danpost danpost

2013/6/11

#
You could add a static boolean to the class and set it to true before using 'stop' to pause the scenario. Then in the world class, add a 'started' method, as follows (using boolean field named 'programPaused' in your actor class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void started()
{
    if (ActorClassName.programPaused)
    {
        ((ActorClassName) getObjects(ActorClassName.class).get(0)).restarted();
    }
}]/code]
Then put the 'continueDoingSomething();' statements in a new method called 'restarted':
[code]// in ActorClassName class
public void restarted()
{
    programPaused = false;
    continueDoingSomething();
    continueDoingSomething();
}
// using this class field
public static boolean programPaused;
In the world constructor, make sure to set 'programPaused' to 'false' or you might get problems during the resetting of the scenario:
1
ActorClassName.programPaused = false;
danpost danpost

2013/6/11

#
What this essentially does, is split the act method into two separate parts. You can put a condition on doing the second part, something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void act()
{
    doSomething();
    doSomething();
    doSomething();
    if (pausing)
    {
        programPaused = true;
        Greenfoot.stop();
    }
    else
    {
        restarted();
    }
}
With this the second part will be executed every time until the game is paused. Then, when restarted, the world class 'started' method will call the 'restarted' method here to do the second part that was not done yet.
You need to login to post a reply.