This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Jon Arnold
Posted Jan 13 - Read on Facebook

Writing a loop like this gives some weird output:

============================
randomPos = ->
print Utils.randomNumber(0, 1)
Utils.interval(2,randomPos)

randomPos()
============================

Every two seconds it will multiply the numbers of times the random number is printed.

I only want one random number every 2 seconds…
Any ideas? Jorn van Dijk Koen Bok Benjamin Den Boer

8 Comments

Seoh Char

check indentation of `Util.interval`

Jordan Robert Dobson

It's recursive. Remove the interval from the function. And just flat out call Utils.interval(....) outside the function.

Then remove randomPos() unless you want it to call immediately.

Jon Arnold

Indentation is done right.

Jordan Robert Dobson

Another option is to leave it as is and use Utils.delay instead of Utils.interval

Jordan Robert Dobson

Basically the problem you had is you were creating a new interval every two seconds that would create another new interval every two seconds which would create two new intervals every two seconds... Just growing and growing every 2 seconds exponentially.

Jon Arnold

Jordan Robert Dobson thank you for your explantion! That makes a lot of sense to me now.

Jordan Robert Dobson

No problem. Feel free to tag me if you need help with anything else, I'll try to do what I can.

Read the entire post on Facebook