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

2016/12/8

stopped()

1
2
Nosson1459 Nosson1459

2016/12/8

#
How and where, do and can I use the Greenfoot stopped() method?
danpost danpost

2016/12/8

#
Nosson1459 wrote...
How and where, do and can I use the Greenfoot stopped() method?
That method is called automatically anytime the user clicks on the 'Pause' button or a 'Greenfoot.stop()' method is executed. It is a World class method, so, therefore, it goes in your World subclass. It can be used to do anything that you want to do when the scenario is stopped.
Nosson1459 Nosson1459

2016/12/8

#
How do I use it? Like this!?:
public void stopped()
{
    // code for stopped execution
}
danpost danpost

2016/12/8

#
Nosson1459 wrote...
How do I use it? Like this!?:
public void stopped()
{
    // code for stopped execution
}
Of course.
Nosson1459 Nosson1459

2016/12/8

#
It's not necessarily of course because this could just be like creating my own method with my own method name.
private void methodName()
{
    // code for method
)
And then in the act I'll have to call it:
public void act()
{
    methodName();
}
Just making sure (not misunderstanding between us): with this I'm NOT supposed to call in the act, right (gets called when stopped)?
danpost danpost

2016/12/8

#
It is not necessary to call it from anywhere, yourself. It is automatically called by greenfoot as stated above. That does not mean that you must not call it from the act or some other method. The code in it might be something that you would want to execute during run time, as well (the scenario will not stop if you call the method programmatically).
Nosson1459 Nosson1459

2016/12/8

#
Thanks, As mentioned above: just making sure (assumed what's above).
Nosson1459 Nosson1459

2016/12/8

#
Is the stopped method run through continuously as a loop while the execution is stopped, or is it only ran through once?
danpost danpost

2016/12/8

#
Nosson1459 wrote...
Is the stopped method run through continuously as a loop while the execution is stopped, or is it only ran through once?
Take a guess.
Nosson1459 Nosson1459

2016/12/8

#
Runs it once? (really?!)
danpost danpost

2016/12/8

#
Nosson1459 wrote...
Runs it once? (really?!)
Now the scenario is "stopped".
Nosson1459 Nosson1459

2016/12/8

#
Exactly that's the point even though the scenario is stopped we could still have a stopped execution method (I think). Can I put a loop in it?
Nosson1459 Nosson1459

2016/12/8

#
Nosson1459 wrote...
Is the stopped method run through continuously as a loop while the execution is stopped, or is it only ran through once?
Nosson1459 Nosson1459

2016/12/8

#
When I put coding in it thinking it's a loop it didn't do what I wanted it to and I didn't see any other problems, so I asked and am still asking to make sure.
danpost danpost

2016/12/8

#
Nosson1459 wrote...
Exactly that's the point even though the scenario is stopped we could still have a stopped execution method (I think). Can I put a loop in it?
You can put whatever code you want in it; but is will only run once for each time the method is called -- and greenfoot automatically calls it one time each time the scenario goes from a running state to a stopped state provided that the method is in a class (or superclass and not overridden) that created the active world being stopped..
There are more replies on the next page.
1
2