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

What is Framer? Join the Community
Return to index
Brent Riddell
Posted Jun 19 - Read on Facebook

Playing around with a game prototype (just for fun) and wondering why this loop only destroys every odd child, leaving only the even numbered ones and not all of them? If I print world.children[i] in the loop, it finds all of them, so I'm confused why it can't destroy all of them :/

5 Comments

Jonas Treub

Probably because you are mutating the array while looping over it

Jonas Treub

Try:
For i in world.children
i.destroy()

Brent Riddell

That worked :) thanks! I'm not that skilled in coding, is it easy to explain what it means to mutate the array? Not sure what i was doing wrong :)

Jonas Treub

By destroying layers the world.children list changes meanwhile you are iterating over that same list.

Brent Riddell

Ah ok, makes sense :) thanks again!

Read the entire post on Facebook