How to have multiple timers?

Hi, so I was working on a game and used the 'timer' block in more than one script. Both scripts are within the same sprite, and both have a 'reset timer' block at the end. And I noticed the longer timer doesn't do anything because the smaller timer gets reset before it. So I was wondering if there was an inbuilt way to have separate timers or if I'd just have to build my own? Thanks in advance.

You can do this to make multiple timers:
set [var V] to (current [time in milliseconds V])
This resets the timer.

Then you can use this to get the timer value:
(((current [time in milliseconds V])- (var))/(1000))

This is a technique that used multiple variables. Does this help?

I may also make a timers library if you want: Snap! Build Your Own Blocks

Hi, I'm looking at what you have shown me and I see that I'd have to make my own separate timers. But I don't quite understand those 2 code blocks you have there. Do you mind explaining those for me?

Which one? The blocks I've embedded on the post? Or the blocks in the link?

Hm?

OOP


demo:

(drag the picture into the snap editor)

what?

Create a variable, then say:
Repeat every 1 second
Increase timer by 1

There is a more accurate way to do this, but it is kinda complicated.
This is much simpler.

It's very inaccurate, the "repeat every one second" uses wait blocks that have a small delay. In a 60 frame rate, Waiting till 60 actually took 61 seconds.

And it does not support decimals. You can see my upper post for an accurate one.

object-oriented programming! that's what my example uses.

a long time ago, i used this in a project

idk who made these blocks...
(similar to @sathvikrias...)

It took my awhile but I think I understand what I was struggling to. Current time in milliseconds is like 534 or 725 etc etc. Which is why it need to be divided by 1000, to turn it into seconds. Thank you all for your help, I think I can take it from here!

very nice! This is SICP-style dispatch-procedure OOP using closures. Note that since last fall with OOP 2.0 you can now also model objects in a more prototypical, data-centric way using the OOP library:

thanks!

oh yeah, I forgot about that. but that's a really good example there, maybe something good for bh to add to the manual when it gets updated.

is there any advantage to doing this one way or another? (is one faster?) if not, what was the reasoning behind adding OOP 2.0?

(sorry, i have updated the link)

here's an optimized version using modern blocks and more logic:

It lacks the pause option, also you need to move the timer forward or backward to get a real one.

"stop" is an option that should work the same as pause.