View Single Post
  #4 (permalink)  
Old January 17th, 2013, 08:49 PM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

It looks like the timers are disabling themselves instead of each other. It should work this way:

Right Timer:
Disable right timer
Enable left timer

Left Timer:
Disable left timer
Enable right timer

That way they basically take turns running. So right fires and enables left. Then left fires and enables right.

I think the way the code is here, they enables themselves and disable the other timer. So if left is the first to go, it enables itself, moves the button, and disables right. Left fires again but the button is already in that spot so you don't see it move.

(Setting breakpoints in the code is an important skill and you should get some practice at it but it's hard to do with timers because their behavior is tied to the clock. If you stop the code, time passes while you step through the code and that can do weird things to the timers' timing. You might be able to do it in this example but only one timer is enabled at a time, but in general stepping through code that is fired by timers is tricky.)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote