Infinite Loop during World generation

So i want to do a Map generator and am currently at making it put out Bodies of water in a Tile Based Enviroment.
So i input a number of Squares that should be turned to water (from the Base that i spawned first) then the program playces a “seed” Water Tile which the other ones can be placed around (to create continious Lakes instead of Sprinkled puddles).
Up to this point it runs smoothly.
But now i want the programm to loop through all available Base tiles, check if its next to water and if so turn that square to water as well. Yes its gonna miss a lot but ever so often it should hit a tile thats next to water increasing the chances down the line until the requested amount of Watertiles has been made
… at least thats the idea…
But i get an infinite Loop error every time, unless i set the parameters for placement so high that it basicly lands on a hit every time (for exsample on a 20*30 map allow the water to be up to 15 tiles away from the next) as soon as i tune it down so the success rate is below aprox. 50% it downright says its infinite altho mathematicly it should resolve after not even uncountably many steps.
How do i solve that Error ?
Can it even be solved ?
Thanks in Advance

Its a bit messy since i tried to squeeze it into one screenshot but maybe it helps

Without spending hours pawing over your code, I can tell you it’s because you’re using while loops.

Can you say in pseudo code ( for every water square I want… ) what you’re trying to do, I can re-phrase your code.

Also I think your random int coming from the array LENGTH, should be coming from the array LASTINDEX, no?

While loops can be scary, agreed. That random node does -1 internally, though - just to make things different & confusing.

While loops in blueprint don’t seem to work the same as while loops in C :slight_smile:

If you’re trying to spawn a water square everywhere there is a field square in a random order, then this would do:

But you’ll never manage it with while loops…

Ah! - I can work with this, gimme a while…

I only read your psudo code after putting that up, gimme a few mins… :slight_smile:

This is closer to what you said, but still wont work, because it has nothing to do when there are no water tiles. ( don’t run it ). Have a look while I re-read your stuff:

And finally! :slight_smile:

331541-ezgifcom-optimize.gif

hmmm ill try to phrase it:

  1. While amount of Watertiles = less than Set Percentage of Land Tiles → 2.Get all Land Tiles → 3. Select Random one → 4. Get distance to all Existing Watertiles → 5. If any is Below 160 (Size of my Tiles + small buffer), Spawn Watertile. If No, Repeat from 3.

Since there is a water tile created in the Previous Function (i tried the code multiple time and cut at different Points, up to here it definitly Works) it shouldnt be infinite here since after a certain amount of itorations its bound to hit close to one …

And yes u are correct i should have used Last Index instead of length to make the calculation precise, sadly that didnt fix the loop problem T-T

That looks really neat and Efficiant … but the whole idea is that i ont want to place a water tile on EVERY Land tile but rather place connected ones until a Threshhold is reached

Either way that small bit of code u put there allows me to start from another angle either way Thanks a lot already :slight_smile:

Thanks a F**kton, it works now, some polishing left but its a huge step forward

You’re welcome :smiley: