Alternative to a Nested Loop
MathPickle
Calgary, Alberta, CANADAMember, PRO Posts: 15
Nested Loops are not currently possible in Game Salad. What is the best alternative to a nested loop? Let's say I wanted to use them to lay out a hexagonal grid after the player inputs "n" - the number of hexagons along an edge. For example... for n = 3 the output would be:
x x x
x x x x
x x x x x
x x x x
x x x
In 2010 FireMapleGames addressed an alternative to nested loops, but an update would be good as his links are no longer active.
Comments
Hi @MathPickle - Joe's demos are now hosted on our site.
Here is the demo you're looking for:
http://gshelper.com/shop/firemaplegames/firemaplegames-for-loop-demo/
EDIT: I'll add a revamp of this demo to my lists.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Wow! That is ugly and beautiful at the same time. Thanks Braydon!
If anyone comes up with something more elegant please post it below - in the mean time I'm off to study Braydon's 2010 solution ;-)
Okay - Here is an alternate solution for nested loops:
Inside an actor called "Spawn Row" use a loop to spawn your first row. Now increment the row index by 1; spawn a new actor "Spawn Row"; destroy the old actor called "Spawn Row". Stop when the row index is big enough.
@MathPickle - Yep, that's the gist of it. There might be an even easier way to accomplish this with the loop behavior (as you said) and the new functions available.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx