How do I get this while loop running?

Get help using Construct 2

Post » Wed Sep 26, 2012 10:45 pm

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.
Posts: 2
Reputation: 779

Post » Thu Sep 27, 2012 9:24 pm

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

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.
Posts: 4,667
Reputation: 37,199

Post » Fri Sep 28, 2012 4:04 am

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.
Posts: 2
Reputation: 779

Return to How do I....?

Who is online

Users browsing this forum: emoaeden, jrobertson789, orugari and 2 guests