[solved] Have a function only run once each day

I’m trying to check how long it’s been since a user visited my app. This will deduct some points in the app and then a face (:slight_smile: 0r :frowning: etc) will be shown in a label that shows the apps emotion.

basically the longer the user has been away the sadder the face will look. Anyways my problem is that I don’t know if I’m calling the function correctly each time a day passes.

basically the check variable check variable changes when the user interacts with something in the app, the last day visited is changed to the current day of the month.

The user can also increase the points of the app when they click a button (+10 points)

right now my app looks like this:

I don’t think its working and I’m not sure why.

here’s a link to the app:


1 Like

How does the stored variable check becomes zero and when?

Hi @muneer thank you! I think that’s were the problem is!

I tried this:

But i’m now running in more circles then before because i’m not sure how to set the stored variable to check only once each day, do you have any advice? or ideas?

1 Like

I think a simpler way to do this would be:

  1. When the functions runs, set a variable to the “current day of the month” (this block can be found in the Device drawer).
  2. To check if the function should run again, compare the variable value to the current day of the month. If they are different values, then run the function.

There are also much more efficient ways to code some of the things in your project… for example, if you have blocks that essentially do this:

If x=1, then set y to 5
If x=2, then set y to 10
if x=3, then set y to 15
if x=4, then set y to 20
…and so on

You can simplify by using math:

Set y to x*5


Thanks @tatiang

I set the variable current day visited to the current day of the month:


the only thing is i check this when the home screen opens so it runs true each time it goes through the if statement:

should I just run the if statement on a unique screen for it? Or do you have any other advice?

Thanks for the help!

You need to use a stored variable. That way it doesn’t reset every time you launch the app. App variables will reset each time.


Thank you! It works now!