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 onceWhat did I do wrong?
The random choice only happens once -- when you assign the variable at the top, then it runs the loop and blinks activelayer
Move the assignment of activeLayer to the top of the loop and it'll do what you want.
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
That's what I was thinking, but if I move it inside, it picks 10 stars randomly, and they all blink at once
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()
I thought every time loop runs, it produces a new content for the variable
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:
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"
Think of it like an arrow pointing left <-
So when you say Utils.randomChoice([...]) what you get is actually one of stars.
Your array is off. You have for i in [0..9] - should be [0..8] which equals 9 items in your array
Not sure why the function version wasn't working as expected, here's version I made that uses the function approach:
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:
ActiveStar().animate properites: ... delay: 0.2
Awesome! Trying it now. Maybe the problem was delay time