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

What is Framer? Join the Community
Return to index
Karina Kozinsky
Posted Jan 12 - Read on Facebook

Dear Framerers! Help needed! I have an array of stars and want them to blink randomly, however, only one random star is chosen and blinks once
What did I do wrong?


Trevor Coleman

The random choice only happens once -- when you assign the variable at the top, then it runs the loop and blinks activelayer

Trevor Coleman

Move the assignment of activeLayer to the top of the loop and it'll do what you want.

Trevor Coleman

Right now the code says:

1. Pick a star at random and assign to activeLayer
2. Do the following ten times:
A) blink activeLayer

It should say:

1. Do the following ten times:
A) pick a random star and assign to activeLayer
B) blink that star

Karina Kozinsky

That's what I was thinking, but if I move it inside, it picks 10 stars randomly, and they all blink at once

Trevor Coleman

Basically the function Utils.randomChoice runs when you call it in the assignment-- it returns a random star.

ActiveLayer isn't the function -- it's just a variable holding the output of Utils.randomChoice()

Karina Kozinsky

I thought every time loop runs, it produces a new content for the variable

Trevor Coleman

You could make that code work by defining activeLayer as a function that returned a random layer... so:

ActiveLayer = () =>
return Utils.randomChoice([star1, star2, ... ,star9])

And then change it to call the function below:


Trevor Coleman

No, the initial statement says "run this function and assign the output to the variable."

Remember that the equals sign doesn't mean "is the same as" it means "assign this value"

Trevor Coleman

Think of it like an arrow pointing left <-

Trevor Coleman

JavaScript is kind of funny this way -- a function basically "becomes" it's output when it runs.

So when you say Utils.randomChoice([...]) what you get is actually one of stars.

Hass Murphy

Your array is off. You have for i in [0..9] - should be [0..8] which equals 9 items in your array

Trevor Coleman

Not sure why the function version wasn't working as expected, here's version I made that uses the function approach:

Trevor Coleman

Oh i figured it out -- you have "options" after "properties" in animate.

there's no "options" -- so the delay isn't being used. just put the delay at the same level as properties.

so it should just be:

delay: 0.2

Karina Kozinsky

Awesome! Trying it now. Maybe the problem was delay time

Read the entire post on Facebook