# \[solved\] Have a function only run once each day

**URL:** <https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067>\
**Category:** Questions about Thunkable X\
**Tags:** beginner\
**Created:** [March 6, 2021, 10:18pm UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067 "2021-03-06T22:18:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![p.powercoders1i0t](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@p.powercoders1i0t](https://community.thunkable.com/u/p.powercoders1i0t)\
**Post date:** [March 6, 2021, 10:18pm UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/1 "2021-03-06T22:18:57Z")

</div>

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 (🙂 0r ☹ 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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/5/a514a75c2ead52ae2213ca4e544e3496cdc6c54d.png)

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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/9/a9a5d1d902526d22968434331244f97d9fcd25b6.png)

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

here’s a link to the app:

[https://x.thunkable.com/copy/8f8ffa07c2ab1635111aad29779e7176](https://x.thunkable.com/copy/8f8ffa07c2ab1635111aad29779e7176)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [March 6, 2021, 11:16pm UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/2 "2021-03-06T23:16:09Z")

</div>

How does the stored variable check becomes zero and when?

---

<div class="post-metadata">

**Author:** ![p.powercoders1i0t](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@p.powercoders1i0t](https://community.thunkable.com/u/p.powercoders1i0t)\
**Post date:** [March 7, 2021, 2:39am UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/3 "2021-03-07T02:39:21Z")

</div>

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

I tried this:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/9/c9ab71520611a7a57ce376bba1eb58a0229f1b80.png)

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?

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 7, 2021, 2:56am UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/4 "2021-03-07T02:56:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![p.powercoders1i0t](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@p.powercoders1i0t](https://community.thunkable.com/u/p.powercoders1i0t)\
**Post date:** [March 7, 2021, 3:19am UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/5 "2021-03-07T03:19:06Z")

</div>

Thanks @tatiang

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

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/9/89816dec29bf94a2a61185ad2856e99f80c04951.png)

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/3/d3583a354828c26199b90a9885adf1c452efea96.png)

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

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 7, 2021, 3:20am UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/6 "2021-03-07T03:20:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![p.powercoders1i0t](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@p.powercoders1i0t](https://community.thunkable.com/u/p.powercoders1i0t)\
**Post date:** [March 7, 2021, 3:24am UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/7 "2021-03-07T03:24:34Z")

</div>

Thank you! It works now!

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 1:29pm UTC](https://community.thunkable.com/t/solved-have-a-function-only-run-once-each-day/1149067/8 "2024-11-08T13:29:02Z")

</div>


