Alternative to a Nested Loop

MathPickleMathPickle 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

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    edited August 2014

    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.

  • MathPickleMathPickle Calgary, Alberta, CANADAMember, PRO Posts: 15

    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 ;-)

  • MathPickleMathPickle Calgary, Alberta, CANADAMember, PRO Posts: 15

    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.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @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.

Sign In or Register to comment.