How do I get this while loop running?

0 favourites
  • 3 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • I'm busy working on a game that has a tiled map. As the player explores the map, it reveals one tile at a time based off line of sight. If a player enters a clearing, the tiled map will populate itself from an array using a flood fill algorithm. I am working on implementing a similar algorithm the one posted below (found on Wikipedia)

    Flood-fill (node, target-color, replacement-color):

    1. Set Q to the empty queue.

    2. Add node to the end of Q.

    4. While Q is not empty:

    5.     Set n equal to the last element of Q.

    7.     Remove last element from Q.

    8.     If the color of n is equal to target-color:

    9.        Set the color of n to replacement-color.

    10.        Add west node to end of Q.

    11.        Add east node to end of Q.

    12.        Add north node to end of Q.

    13.        Add south node to end of Q.

    14. Return.

    I am having difficulty getting the while loop to work properly in Construct 2. Either the while loop runs, but never populates new objects into the layout, or it freezes entirely (for unknown reasons). I've had a really hard time finding the problem in my logic. I'm far more used to traditional coding so this is a new experience for me.

    If someone could take a look at the .capx file I've linked to and show me where my problem is I would appreciate it.

    dropbox.com/s/mltckrw8wnjpks5/Sample%20Project.capx

  • I did a flood fill in the second capx in this post:

    http://www.scirra.com/forum/in-something-enclosed-or-is-it-just-me_topic53841_post340661.html#340661

    I made it so it can flood fill repeatedly over the same array without having to reset it's contents. n is the target-color and n+1 is the replacement-color.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks! I finally got my code working properly. Those examples of other flood fill implementations were really helpful.

    It's really great to have such knowledgeable and helpful people on the forums.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)