Multiple timeouts not working? #366
Replies: 6 comments
-
Posted at 2015-04-27 by @gfwilliams Well, one guess is that (like in a browser) To fix it, try:
There are other ways to do it, but that one is probably the most readable. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-04-27 by @gfwilliams Just to add that this is pretty much standard JS. For example:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-04-27 by joppiesaus Thanks a lot! I often forget those kinds of things. Now it works! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-04-27 by @allObjects @gordon, didn't you recently add .bind()? Would that now be even a better option - resource-wise - and for sure from a point of avoiding globals...? I guess the code would then look like this:
Adding this .bind() was a great move! Still have to get used to it having started JS with 1.3... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-04-27 by @gfwilliams Yes, that works too - and as you say it's more efficient. It's just that it's not very readable if you don't know what |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-04-28 by @allObjects ...not because I say it, it is because you @gordon made it so! - Credit where - to whom - credit is due! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-04-27 by joppiesaus
So I'm still enjoying to work on my fruitmachine, but the way I implement multiple timeouts don't seem to work correctly.
Basically, I've 3 LED's, or fruits - or wheels, and I stop them one by one in order of time. When I spin the wheel, I tell it when to stop spinning. It works by just setting the velocity of the wheel to 0.
Then you have the
stop
functionThe spinning happens when the user clicks the button. At that time,
spin
is called(notWheel.spin
)But, only the last
setTimeout
seems to be called.What am I doing wrong?
Here's the full code.
Beta Was this translation helpful? Give feedback.
All reactions