Run Function Every So Many Seconds

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

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

Thanks, good idea, I’ll try that.

Did this work for you @athornock??

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.

1 Like

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.

1 Like

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!!

1 Like

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.

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.

1 Like