How do you store a timer value in Tiny databases

I want to use a tinyDB to store the value of a timer when switching screens so that the time will continue from the point where the user leaves the screen, can someone teach me how to do such a thing?

You cannot store a clock instant in the tinydb. You can store a string of the date/time then convert it back to an instant on the other screen.

If your "timer" is just counting up / down with a number, then save the number to a tinydb tag, then call this tag back in the other screen as the start value for your other timer.

Store the start time in millis in TinyDB... you then can calculate the elapsed time easily...

Elapsed time = current time - start time

Taifun

I'm storing the timer data as a number that counts up. But i don't know how to call the value of the TinyDB and increment the timer after getting the value. Btw it isn't a visible clock rather I guess you could call it a hidden timer that increases by 1 every second..

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

I'll send it in a bit

Something like this?
ezgif.com-gif-maker

every time the counter changes, save it to tinydb.
when Screen.initialize, read the counter from tinydb, and make it counting from that number.

Try this one:

Is this what you are looking for?

It is similar but what I had in mind was the timer is only in screen1, and when you change to screen2 it stops, after you come back to screen1, the value of screen1's timer continues from where you left off.

No but thank you

Ok, but should it continue counting there after restarting the app or should it start again at 0?

I would make it restart after closing the app

show us the code you have done, at least we need to know how it counts, then we can direct you the right way.

As, every HTTP requests can be logicaly grouped using sesion object, here, also every screen call is a seprate call, what about, calling/opening new screen with parameters, as

Here you can check both options:

ezgif.com-gif-maker (1)

(Video showed in 1.5x times faster)

How about showing your blocks in full so that other users can more easily follow your approach?

1 Like

This is just my simple logic...

Sure, but what does this have to do with the solution marked in post #15 (which at least was previously marked as a solution)?