# Run Function Every So Many Seconds

**URL:** <https://community.thunkable.com/t/run-function-every-so-many-seconds/554425>\
**Category:** Questions about Thunkable X\
**Tags:** solved\
**Created:** [April 3, 2020, 7:50pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425 "2020-04-03T19:50:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![athornock](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@athornock](https://community.thunkable.com/u/athornock)\
**Post date:** [April 3, 2020, 7:50pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/1 "2020-04-03T19:50:36Z")

</div>

Hi,  
I’m trying to run a function every 7 seconds to change a background picture of a button. It works, but it slows everything else down or stops everything else from functioning in my app entirely. Is there a better way to do this? I’ve tried using the forever loop and the while loop:

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/7/47121705e42474b7dc4f4004ed3846d29bfb3fee.png)

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [April 3, 2020, 10:33pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/2 "2020-04-03T22:33:46Z")

</div>

> [@athornock](#):
>
> ng else down or stops everything else from functioning in my app entirely. Is there a better way to do this? I’ve tried using the forever loop and the while loop:

you could try taking out the repeat while block and replace it with an if/then statement. if true, do stuff. else, nothing.  
immediately after the 7second delay, place a block to run the function `changePublicVideo`

 ![Screen Shot 2020-04-03 at 6.22.27 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/4/44f7ccd6300ef7aaed53396847cca9982875e0c7.png)

---

<div class="post-metadata">

**Author:** ![athornock](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@athornock](https://community.thunkable.com/u/athornock)\
**Post date:** [April 3, 2020, 10:37pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/3 "2020-04-03T22:37:38Z")

</div>

Thanks, good idea, I’ll try that.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [April 3, 2020, 11:28pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/4 "2020-04-03T23:28:51Z")

</div>

Did this work for you @athornock??

---

<div class="post-metadata">

**Author:** ![athornock](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@athornock](https://community.thunkable.com/u/athornock)\
**Post date:** [April 4, 2020, 2:48pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/5 "2020-04-04T14:48:45Z")

</div>

I’m not totally sure yet. It appears to have, but there may have been another issue too. I’m going to finish building out the page and try it both ways and report back.

---

<div class="post-metadata">

**Author:** ![athornock](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@athornock](https://community.thunkable.com/u/athornock)\
**Post date:** [April 7, 2020, 1:51pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/6 "2020-04-07T13:51:40Z")

</div>

It looks like it works now both ways. There must have been some other issue on my page. I’m wondering if it’s the Realtime DB listeners.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [April 7, 2020, 1:54pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/7 "2020-04-07T13:54:17Z")

</div>

Who knows! Keep in mind anytime you actively work eith cloud Variables to expect a slowdown. But, I’m glad to hear you got it working!!

---

<div class="post-metadata">

**Author:** ![gobassky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/gobassky/32/77019_2.png) [@gobassky](https://community.thunkable.com/u/gobassky)\
**Post date:** [July 31, 2020, 1:02pm UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/8 "2020-07-31T13:02:06Z")

</div>

You may want to try the timer (under sensors) block to trigger a function at set intervals, in your case is 7 seconds. Then you don’t have to deal with messy while loops.

---

<div class="post-metadata">

**Author:** ![athornock](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@athornock](https://community.thunkable.com/u/athornock)\
**Post date:** [August 1, 2020, 1:32am UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/9 "2020-08-01T01:32:20Z")

</div>

Great idea, thanks.

I actually ended up creating a web page for that component in my app. The page handles the transitions and isn’t very expensive processing wise.

---

<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, 11:39am UTC](https://community.thunkable.com/t/run-function-every-so-many-seconds/554425/10 "2024-11-08T11:39:17Z")

</div>


