Count up timer?

I posted this question as part of another about text messages but I want to separate it out.

Can someone share a screenshot of a working count up timer? I’ve looked through the forums and so far haven’t found one from Thunkable X that just displays a timer that counts up each second.

@tatiang . Here’s a simple example:

You don’t really need to set the 'Count up' property via the blocks. You can just set it in the designer. I just put it here for completeness.

Here’s a link to copy the project, if you want: Thunkable

1 Like

Hmm. @Mark, I had the same code. But when I add a Wait 1 second block at the bottom of the forever block, instead of counting up by 1 each second, the timer counts by 500 or more per second. And it’s not even consistent and then it stops at 5000. What’s going on? :crazy_face:

Edit: sorry, you had milliseconds while I had seconds. Now it’s working. How strange. Yay! But… uh… it stops at 5 seconds. Ah, okay, I had to change the interval. Kind of confusing that “interval” is actually the length. I would think of interval as the loop durations (e.g. 1 would be a timer that ticks every 1 second, 15 would be a timer that ticks every 15 seconds).

Here’s the code for a count up timer that ticks off every second (interval set to some high number):

@tatiang, If you just want to count up seconds you don’t really even need a Timer. Just a loop with a 'Wait 1 seconds' in it and increment a variable within the loop.

FYI, 'Interval' is the loop duration. Of course you have to set 'Loops' to be true, otherwise you just get one iteration of the loop, whose duration is, well, 'Duration'. Also, note that the Timer doesn’t have the notion of ticks, per se. However, you can get the amount of time that the current loop of the time has been running (or remaining, depending on if you are counting up or down), in either seconds or milliseconds.

Hope this helps.

-Mark

I think I was scared off by the recent discussion about how slow Forever blocks were so I avoided the obvious answer: incrementing a variable within a loop. But in practice, it seems fine for the timer I need.

Does a loop with ‘Wait 1 seconds’ actually work? Here’s what I tried and I get a timer that counts by 5 or 6 or 7 or 8 – it’s not consistent – every second.

Screen Shot 2020-01-03 at 8.17.40 AM

Here’s a fun little timer. Try changing the increment value to a decimal and watch it freak out.

https://x.thunkable.com/copy/033076d0f0e97867eb2ada3e9d44d9fe

I’ve gotten values like this (in order): 0, 1, 1.5, 2.5, 2.5, 2.5, 2, 3, 3, 3, 3, 3, 3, 3, 3.5, 3, 3, 2.5, 2, null, 2.5, …

The expected values each second should be (in order) 0, 0.5, 1, 1.5, 2, 2.5, 3, etc.

It also seems that the previous increment value (e.g. 0.5) affects the next choice of increment value. That is, if I use 0.5 for each second, I see a certain series of numbers like the bizarre one above. If I then change the increment to something else like 50, I see a new series. Finally, if I change the increment back to the original value of 0.5, the series is much different with values like 0.9, 47, 2, 36, 50, etc., or even long decimals like 104.00000003.

Oh and a Repeat block is even worse than a Forever block. In that case, it increments about 100 each second for an increment value of 0.5.

1 Like

you know, that looks like it should work @tatiang - is there any chance you could just use a timer for this instead rather than waiting and looping like this?

Maybe. That’s the route I took after I posted this. But I’m a little disturbed by the fact that a loop block doesn’t behave as I’d expect it to. I tend to base a lot of my app development on predictable math.

Can you explain why the forever+wait 1 second blocks don’t actually do that?

Try using normal variables and rounding values, which is required for operations with real numbers.

@actech When you say normal variables, you mean “app” variables, right? I’ve done that. That’s what I started with. And I don’t see how rounding would fix this but I did just try that and it still provides unpredictable results.

изображение

I wish that worked but I still get unexpected results. I’ll post a video in a minute.

(I had used the Round block but I changed it to “with __ decimal places” after you posted that.)

https://x.thunkable.com/copy/06d9461757f8da84dc52bebe55d3ced0

So in this case, the timer is doubled. When IncreaseBy is 1.0, the timer add 2 every second. Easy enough to fix but still not valid for the code I created. And without rounding, it’s just a mess.

If my example does not work for you, it is better to use a different approach. I don’t look at projects that use app-variables.

@tatiang There are some weird (and unfortunate) interactions with the wait block when you are in the companion and are editing your app. Two things to try would be to kill and restart your companion app after each change and see if you continue to see the issue and also to download and install your app and see if the problem persists. Let us know the results of those experiments.

-Mark

It does seem to work correctly with the code below if I force quit and re-open the Thunkable Live app after I make each change to the “change by” value. But the demo I posted a link to is still doubling the timer value.

Screen Shot 2020-01-06 at 6.47.55 PM

@Mark So… my adjustable timer works perfectly when downloaded to my phone. So that’s at least good.