How to Create Realtime Background Countdown?

If I Give One Button Where Click button Then Start Countdown Even Close The App.

It Is Possible in Niotron ?

Looks Like this

Screenshot 2023-04-08 194253

why do you want background time? you can use with with just network… no need of any extension

1 Like

How its possible ?

Take clock
Set time ALWAYS FIRE to FALSE
set clock TIMER ENABLE to FALSE

set the block
WHEN BUTTON1 CLICK >
SET BUTTON1 ENABLE TO = FALSE
SET CLOCK TIMER ENABLE = TRUE

Set block
WHEN CLOCK TIMER DO
SET GlobalClock TO > 0 (you must take variable)
SET GlobalClock TO > (tag)GlobalClock + 1
SET LABEL TEXT TO = (tag)GlobalClock
IF GlobalClock(tag) = 60 (in second it is 1 minute, set as you like)
SET BUTTON1 ENABLE TO = TRUE
SET GlobalClock TO 0

1 Like

@HR_Hmingsangthang Shouldn’t ALWAYS FIRE be TRUE for it to work in background? :thinking:

If you set ALWAYS FIRE = TRUE clock will stop when the app is closed.

To run on background set to FALSE.

But this might not be much secure because everytime user click they will CLEAR CACHE the app, time will begin from 0 again thats mean they can click BUTTON again.

To make secure :slightly_smiling_face:

When user signup finish
(take global variable name timer)
CALL DATABASE
STORE TAG > TIMER
STORE VALUE > globaltimer(tag)

set block
WHEN BUTTON CLICK
SET BUTTON ENABLE FALSE
CLOCK TIMER TRUE

WHEN CLOCK TIMER DO
SET timertag TO timertag + 1
SET LABEL to timertag
IF timertag = 60
CLOCK TIMER ENABLE = FALSE
FIREBASE STORE VALUE
TAG= TIMER
VALUE = timertag

WHEN FIREBASE GOT VALUE
&
WHEN FIREBASE GOT CHANGED

SET:
IF (gettag) = TIMER
(nested if)
IF (getvalue) = 60
SET BUTTON1 ENABLE = TRUE
SET timertag TO 0
ELSE
SET BUTTON1 ENABLE = FALSE

1 Like

So I’m kind of confused, the block description shows this:
screenshot

Please test that blocks.

First set to FALSE, close application, if timer is not working in background. You may need extension.

1 Like

@HR_Hmingsangthang If I close the app no clock works, for that an extension is needed, but if I go to another apps (without closing mine) the clock will work only if AlwaysFire = True

2 Likes

As already mentioned in another community

store the start time in TinyDB and in Screen.Initialize calculate elapsed time = current time - start time
As you can see, like this here is no need to have something running in the background…

Taifun

1 Like