This content has been marked as final. Show 3 replies
On your stop button you are creating a new instance of the timer, so it has no connection to the one you created with the start button (sorry if my terminology isn't right...I'm no master of this parent script stuff).
If you do a little debugging with a few put statements (with a me thrown in there) in the timer script you'll see
-- "new timer"
-- "resetTimer <offspring "timer" 3 4b1d2c0>"
-- "runTime <offspring "timer" 3 4b1d2c0>"
-- "new timer"
-- "stopTimer <offspring "timer" 3 4b67830>"
-- "reportTimer <offspring "timer" 3 4b67830>"
The start button resets and runs, but the stop button stops and reports from a different instance (or parent?).
I could easily do this with behaviors, but am weak on parents so am not 100% how to access those sort of things without using globals (which i stopped using when Dir6 came out :)
Also, I tend to use 'the milliseconds' or _system.milliseconds now, rather than ticks (personal preference).
I have a feeling many others are better at answering this one...
Here's a timer object that I had created for another project that would work perfectly:
set timer1 = new (script "timer")
set timer1 = script "timer"
This means that the calls will be sent directly to the script itself, rather than an instance of the script. Both buttons will therefore by talking to the same object: the "timer' script.
This also means that you can only ever have one timer running at a time. If you need to have multiple timers running, then you will need to create a separate instance for each timer, using the new() method. You will also have to store each instance in a property or a global variable so that the runTimer() and stopTimer() commands can be sent to the same instance.
On a different point, you wrote:
> the ticks/60 --ticks (1 tick = 1/1000 of a second)
A tick is in fact 1/60 of a second. Use "the milliseconds" if you want value accurate to 1/1000 of a second.