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

What is Framer? Join the Community
Return to index
Marc Krenn
Posted Aug 07 - Read on Facebook

Can someone help me out on this one?

Download:
https://dl.dropboxusercontent.com/u/7997357/framer/marc/zips/Universe.zip

It's about creating an array of layers - you'll find more info within the code. Yes, I still haven't figured it out, Tisho :(

I feel so ashamed and stupid but almost all descriptions & documentations of array-functions and comprehensions seem to be completely irrelevant to what I'm trying to achieve.

Thanks!

3 Comments

Tisho Georgiev

You're doing great so far. What you have there is actually a completely valid use of comprehensions. The only thing you forgot to do was to return "planet" from your birthPlanet() function. Put just the variable name "planet" as the last line in your function, or "return planet" if you want to be a little more explicit.

CoffeeScript's list comprehensions are a quick way to aggregate the results of function calls into an array. You used the syntax for the comprehension correctly, but your function isn't actually returning a result. Now in CS, returns are implicit, which means that a function will just always return whatever the result of its last statement was. In your case, that was the planet.style assignment, which just returns planet.style if the assignment was successful. If you put a "print cluster" line at the bottom of your file, you'll see the debug console show up and list a bunch of borderRadius definitions. What you need, instead, is a list of layers, so you need to return the actual layer. I've already explained to you how to do that :)

You might want to take a look at the coffeescript cookbook for examples of working with strings, arrays and the like: http://coffeescriptcookbook.com/.

Marc Krenn

Thank you sooo much, Tisho! It works flawlessly! I think that makes it at least two cups of coffee now ;)

Just to make sure I really get it this time:
So, 'return' defines what the "result" of a constructor/function is - in this case an 'object' (=layer) called 'planet'. If no specific 'return' is defined, Coffeescript will assume the last line of code is the desired "result" and therefore will return this bit whenever you're referring to this function.

Another head scratcher is:
planets = (birthPlanet() for planet in [0..planetCount])
# changed the name of the array from 'cluster' to 'planets'

planets ....................... name of the array
birthPlanet() ............... function called for ...
planet ......................... this is pretty much a "counter" for the range of ...
[0..planetCount] ......... a range form 0 to 30 in this case

I'm assuming the 'planet' part (the "counter") could be replaced with any other "name" (like 'i' or 'counter') and is purely non-functional, unless I want to do something like:

planets = (birthPlanet(planet) for planet in [0..planetCount])

?

Tisho Georgiev

You are exactly right :)

Read the entire post on Facebook