I have a simple(?) loop problem that I come across a lot.
I want to loop through an array and hand over the object to a delay function.Example: Changing these 5 boxes in a sequence after each other.
for card,i in allcards Utils.delay 1*i+1, -> card.backgroundColor = Utils.randomColor()
unfortunately, the delay function only accesses the last card. How can I hand the correct card into the delay function?
issue in line 13 and line 24
fat arrows...keep context.
how fat? => doesn't workhttp://cloud.eckert.io/2Z00062n0H1o
We talked about this at our last meetup.
Here's the code: http://share.framerjs.com/nqeoakxnf8dd/
It just doesn't know what card is most likely after the loop is over. Does @.name work?
try passing card as an argument to the function that is executed on delay.
Johannes, have you figured it out? I couldn't, so I'd love to see the working file. Thanks :)
Wait so this isn't fixing the problem?
Aren't you trying to print card.name?
Maybe I am missing something?
Maybe I just saw the error on your click event inside the loop and focused there.
Utils.delay is shorthand for underscore's _.delayBut it looks like Framer isn't forwarding all arguments into the delay function.
If I call _.delay directly, I can pass card into a function that manipulates the cards:_.delay(changeCard, timedifference*1000, card)http://underscorejs.org/#delay
maybe something to look into Koen?
Here's how I solved it... http://share.framerjs.com/moromlxqcruu/
Change the `for ... in` loop to allcards.forEach:
allcards.forEach (card, i) -> Utils.delay 1*i+1, -> card.backgroundColor = Utils.randomColor()
Why it happens? Closures.
Just pass it to a function... that's an easy way to take a value out of that scope.
This is really fun! I was wondering how would you code to implement random images instead of colours?
Here is my attempt with images, but can't get it to workhttp://share.framerjs.com/whul9yr6loum/Help anyone?