[Newbies] Re: Implementing a simple timer
andreas.raab at gmx.de
Fri Dec 16 08:04:28 UTC 2011
There is absolutely no guarantee how often #step will actually be
called. The given #stepTime is just a recommendation to the system. To
make your code work you should use something like:
"Start the timer"
timerStarted := Time totalSeconds.
"Update my timer"
self time: Time totalSeconds - timerStarted.
On 12/15/2011 23:51, Jan Teske wrote:
> I'm trying to write a simple timer using a TextMorph and its step
> method. It should count up every 1 second so I've set stepTime to 1000.
> My step method looks as follows:
> self time: self time + 1.
> self contents: self time asString
> That should work. But I discover one problem: The timer counts up but it
> does so way to fast. If I print the numbers onto the Transcript
> everything works fine. So I think the problem lies within the TextMorph.
> It seems that during the sent of 'self contents:' the step method is
> called again so that it is executed long before the stepTime is up.
> Am I right with that suspicion? Can anyone think of a way to work around
> my problem?
> Thanks in advance!
More information about the Beginners