Tutorial - How to disable a component for an hour/day


Some apps allows the users to get some extra credits by pushing a button or doing something every x amount of time. Example: Candy Crush let’s you roll a fortune wheel every 24 hours. In that period, the component that gives prizes should be disabled.

If you need something like that in your app, you might find this tutorial very useful.
In this case we will use a button. Each time the button is pressed, it will not be able to be clicked again for an hour. Of course, you can adapt this to your app and change the button for any other component, event or procedure that you need to disable.

Components you are going to need:
One button.
One clock.
One TinyDB.

The clock properties should be:
(1000 milliseconds = 1 second, so this clock when enabled will call the Timer event every 1 second).

When the button is clicked, you are going to save in TinyDB the instant in milliseconds.

Note: The Clock.Get Millis block returns the current time in milliseconds since Unix Epoch (January 1, 1970, 0:00 UTC). Learn more here: http://currentmillis.com/
It’s basically a big 13 digits number that is incremented by 1 every millisecond (or you can say it’s incremented by 1000 every second).

Also, when the button is clicked, you have to disable the button and start a clock that will check if the current millis are greater than the millis saved in TinyDB + 360000 (that’s one hour in milliseconds).

So this is the click event blocks:

Next we need to make the timer event (clock) that will check every second if the time elapsed since the click is greater or equal to one hour.

So we compare the current millis to the millis saved in TinyDB when the button was clicked plus 3600000.
If the current millis are greater or equal to the millis saved + 3600000, it means an hour or more has passed since the click, so we do the following:

  1. Enable the button
  2. Stop the clock
  3. Delete the time saved in TinyDB, because we don’t need it anymore.

This is how the Timer event will look:

Finally this is the part that makes the trick interesting. We need to make sure that if the user quits the app, and opens it again, the button remains disabled until one hour or more has passed.

So we initialize the app asking if the tag LastClickMillis is not empty.
If it’s not empty, that means the button was pressed less than an hour ago, so we disable the button, and start the clock.

If it’s empty, it means that the button was not clicked in the previous session and it should be enabled on start.

This is how the Initialize event should look:

If you want to try it and not have to wait an hour, change the 3600000 for 60000, that will make the button wait just one minute to show up again. You can exit the app and open it again within that minute to check that the button remains disabled.
After a minute has passed the button will be enabled again.

As a challenge, we can research how to prevent the user from resetting the clock by deleting the app’s data in the device’s settings. Or how to deal with a cheater user that advances the device’s clock to enable the button before the time has passed.

How to disable button1 on screen1 when
How to make button enable and disable with countdown timer
Complete a process once in a day
How to get international times from Internet?
Help In Disable Component
Need help problem
How to disable button1 on screen1 when

Nice tutorial @Italo :+1:


Very simple and useful, @Italo

Task Hour/Day + Countdown Timer + Prevent Hacking

time is milisecond or second?


For more simplicity and to avoid extra blocks that are not needed, I opted to save it as milliseconds, but if you want to use seconds, divide the milliseconds by 1000.


can i show time count in the screen for help user to see time,when time count start from 1 hour to 00 second.
is it possible using tiny db?


You have to use a clock to do that. TinyDB only stores the time. The clock is the one component that will be called every second to update the label with the time left.


but how to do?can you please give the blocks?
it will helpfull


If anyone increase system time.then he/she need not to wait until 1 hours.users can hack this easily.how to do it without system time.
can you try please using time interval where user can not be able to hack.



is it possible do this within tinydb?


The above example makes use of a TinyDB.


but if anyone increase system time,they can not wait given times.


@maksud, l recommend you to actually practice the given example if you really want to create the related app, asking around without practicing wouldn’t let you go anywhere and our advices here would mean nothing.

So, start practicing and in no time you will master it since AB is easy.


Thank you for your recommendation.
i also try to practice all time.


Can you explain how to do timer using firebase


I don’t know anything about Firebase, sorry. Never used it yet. May be somebody else can help with that.


Timer using firebase? I haven’t heard any method about it using AI platform. I know that there is method to ask for server timestamp (https://firebase.google.com/docs/reference/js/firebase.database.ServerValue) but currently there is no way to do it using AI. Of course, you can achieve this using php server.


i used tiny db method bit they are showing error(milies cant accept the argument date,year)


Italo, we are kindred spirits. I hate Firebase too lol :fire: