Basic timer question

Since the current WDC is all about timers, I thought I’d ask a really basic question. The timer component has always confounded me. For example, why doesn’t this change the value of the label?

My timer is set to count up with an interval of 1. When I preview it, it just shows “1” and doesn’t change.

I realize I could change the value of a variable each time the timer fires but I’m specifically trying to understand what the “Timer1’s Time in seconds” block is for. Shouldn’t it hold the elapsed or remaining time?

2 Likes

There must be something fundamental I don’t understand about timers because this doesn’t do anything, either:

It would be great if the documentation had a working example.

2 Likes

The short answer is enable the three switches in the timer. I find it working this way.
image

2 Likes

I tried that but it still isn’t working for me.

Edit weird. Now it’s working.

Sometimes the lag in previewing changes really throws me off.

1 Like

Agree :grin:

So it seems like setting those values in blocks doesn’t work but setting them in the Timer gear menu does. And the timer won’t run at all without Loops set to true.

1 Like

I saw the loop switch is the controlling one. It false then it triggers once, if true it keeps on triggering but just to avoid any other unexplainable situation. I set all to true.

The documentation needs a lot more detail. For example:

Does “Loops” set to true mean that the timer triggers every interval that it’s set to (e.g. once per second)? That’s what I’m assuming but my first instinct is that it mean the timer would reset to 0 after reaching some value (e.g. 60 seconds total) or reset to its starting value once reaching zero if counting down.

The component might better be called something like “metronome”* because the green “Timer1’s Time in seconds” block just vacillates between 0 and 1 when the interval is set to 1 second.

*Although this is probably just my ignorance as a programmer…

3 Likes

@tatiang,

To see how I coded the timer, remix my project and go to the Mitochondria Masher screen.

Hope that helps.

2 Likes

I think so, but I’m not sure.

You can also check the Thunkable Documentation for more info.

Hi there,

If Loops is true, the timer will fire repeatedly.
If Loops is false, then the timer will not continue to fire after it next fires (so I can create a timer, loops = false, it will fire once and no more).
I can clarify this in the docs, but we probably won’t change this property’s name.

I’ll check in with the team about the original topic of the time in [seconds|milliseconds] blocks not returning the expected value.

4 Likes

Yes, this is how I understood it.

That was my explanation.

2 Likes

I appreciate you explaining it as well!

@tatiang I have updated the Timer docs with a more detailed description of the Loops function. Please check it out and let me know what you think!

4 Likes

That’s really cool @jane . Could you also update the Count Up function a little bit? It’s probably just me, but I don’t really understand what Count Up is and how it works.

1 Like

The Time in [seconds|milliseconds] blocks don’t work exactly the way you have programmed them here.

This block will return the remaining time on your Timer’s interval.

So if your Timer’s interval is 5 seconds, this block will count down 4, 3, 2 1, 0.

If your timer’s interval is 1s, and you show this value when the timer fires, it will always show 0, as there are 0 seconds remaining on the Timer.

Here is an example of how your Timer could be set up, and how you would work with it in the blocks:

You can see a project that demonstrates how to use these blocks here

This is now explained in the Timer docs. Thanks for asking about it!

5 Likes

Looks good! Thank you for updating that.

@jane I think the link you posted right above might be a private project. I can’t open it.

3 Likes

Unable to open the project @jane .

1 Like

this is the setup i use that works for me:

  1. from the design tab, set up the timer component to have an interval of 1sec, set it to count down, set loop to true and set enable to false.
  2. before you start the timer, set a variable timer_val to the desired time duration (in seconds); also set enable to true
  3. start (call timer1’s start)
  4. when timer fires (ie. it just counted down 1 sec, as defined in the component setup), then it’s time to reduce the timer_val by 1. when timer_val has gone down to zero it’s time to stop the timer (ie. call timer1’s stop) and set enable to false.
  5. if you set a new variable display_val = timer_val and show it for display, the time will show as counting down.
  6. HOW TO COUNT UP? use the same set up as above but always compute this when timer fires.
    set the display_val = ORIGINAL_DURATION ENTERED MINUS TIMER_VAL
2 Likes

@tatiang @codeswept I apologize! You should be able to access the project now.

4 Likes

Great, thanks @jane !

2 Likes