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

#
What can I do to make it loop, but then stop looping when run is clicked (when I put in a while loop I couldn't press pause)?
danpost danpost

2016/12/8

#
Nosson1459 wrote...
What can I do to make it loop, but then stop looping when run is clicked (when I put in a while loop I couldn't press pause)?
Show what you tried.
Nosson1459 Nosson1459

2016/12/8

#
public void stopped()
    {
        stopped=true;
        stoppedTime=System.currentTimeMillis();
        while (1 != 0)
        {
            middleTime=System.currentTimeMillis();
            elapsedStop=(middleTime-stoppedTime)/1000.0;
        }
    }
danpost danpost

2016/12/8

#
Nosson1459 wrote...
< Code Omitted >
That, lines 5 through 9, is an infinite loop within the method. As long as the stopped method is processing, the 'Pause' button will remain and be unclickable. You will need to go to the debugger and force a termination of the running of the project before you can do much else.
Nosson1459 Nosson1459

2016/12/8

#
Why is it starting the loop if It's not being paused (can't press it (disabled almost))?
danpost danpost

2016/12/8

#
Nosson1459 wrote...
why is it starting the loop if It's not being paused?
It does not loop by itself -- you added the loop. The method will be executed when called. If you add a loop into the method, it will execute it. If it is an infinite loop, sobeit -- it will run forever if you let it. Once the method completes its execution (any loops would then be completed within it as well), then the scenario will be in a stopped state (if not programmatically called within your project). No code within the project will be executed until it is restarted or the 'Act' button (or its shortcut key) is pressed (or you manually call a method or constructor).
Nosson1459 Nosson1459

2016/12/9

#
I think I figured out a solution without using a loop, it uses the stopped() method and started() method. The started() method is the same thing as stopped(), just it gets called right after "Run" is pressed? (Just to be sure)
danpost danpost

2016/12/9

#
Nosson1459 wrote...
I think I figured out a solution without using a loop, it uses the stopped() method and started() method. The started() method is the same thing as stopped(), just it gets called right after "Run" is pressed? (Just to be sure)
I was wondering if you would figure that out or not. Now, see if you can get it to work properly.
Nosson1459 Nosson1459

2016/12/9

#
I got my timer to work (go to Score Timer discussion ).
You need to login to post a reply.
1
2