How are actors selected in for loops?


  • Posts: 176
Just curious, when you count every actor using a 'for' loop, how are they selected? In other words, if I randomly place 5 actors one at a time on a scene, and then execute a "For each actor on screen" or "For each actor of group" (Assume they're all in the same group) loop, which actor will be counted first, second, third, fourth, or fifth, and why?

Is there some invisible array/buffer/list that contains all the actors and Stencyl just picks from it in a 0 to total size kind of fashion?

« Last Edit: August 09, 2019, 04:21:54 pm by Omniso »


  • *
  • Posts: 2168
I'm also intrigued to know the answer.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.


  • *
  • Posts: 2525
You can view the block code to see their respective lists. For example, 'For All Actors on Screen' loops through engine.allActors and skips the ones that are not on screen. The order that actors are added to these lists depends on the list, but is what you'd probably expect. allActors, for instance, is populated as actors are created.

If you want to loop through actors in a particular order, you can place them in a list then sort the list according to some criteria: x/y position, an ID you assign, etc.