• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Loop not working, has diminishing return results

Status
Not open for further replies.
Level 14
Joined
Dec 24, 2008
Messages
2,126
Hi, I'm having a strange problem with a loop trigger I made recently, the idea is as follows:
10 trees are spawned randomly across the map at initialization, those 10 trees will spawn another 100 trees each, one after the one, forming a chain to simulate a randomly generated forest.
To do this, I used a Loop from 1 to 10 and another inside it from 1 to 100, this worked correctly and I can generate random forests across the map.

The problem was when I tried to add additional biomes to the loop, so that at begining, it will create 10 Summer Trees, 10 Snowy Trees, 10 Barrens Trees, etc, etc, and thus generate a biome for each.

For some reason, this didn't work, and instead, only the Lordaeron Summer biome was generated, and a very small fraction of the snow biome, as if the loop was diminishing, none of the other biomes was generated, I'll paste the triggers below to show how it works, any idea for why is it doing that would be appreciated!

  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set BiomeType[1] = Summer Tree Wall
      • Set BiomeType[2] = Snowy Tree Wall
      • Set BiomeType[3] = Barrens Tree Wall
      • Set BiomeType[4] = Fall Tree Wall
      • Set BiomeType[5] = Ruins Tree Wall
      • Set BiomeType[6] = Ashenvale Tree Wall
      • Set TerrainType1[1] = Lordaeron Summer - Grass
      • Set TerrainType1[2] = Lordaeron Winter - Snow
      • Set TerrainType1[3] = Barrens - Desert
      • Set TerrainType1[4] = Lordaeron Fall - Grass
      • Set TerrainType1[5] = Sunken Ruins - Sand
      • Set TerrainType1[6] = Ashenvale - Grass
      • Set TerrainType2[1] = Lordaeron Summer - Dark Grass
      • Set TerrainType2[2] = Lordaeron Winter - Grassy Snow
      • Set TerrainType2[3] = Barrens - Dark Desert
      • Set TerrainType2[4] = Lordaeron Fall - Grassy Dirt
      • Set TerrainType2[5] = Sunken Ruins - Dirt
      • Set TerrainType2[6] = Ashenvale - Leaves
  • For each (Integer C) from 1 to 6, do (Actions)
    • Loop - Actions
      • For each (Integer A) from 1 to (Random integer number between 7 and 15), do (Actions)
        • Loop - Actions
          • Set RandomLocation = (Random point in (Playable map area))
          • Destructible - Create a BiomeType[C] at RandomLocation facing (Random angle) with scale (Random real number between 0.80 and 1.20) and variation (Random integer number between 0 and 9)
            • For each (Integer B) from 1 to (Random integer number between 75 and 150), do (Actions)
              • Loop - Actions
                • Set LastLocation = ((Position of (Last created destructible)) offset by (Random real number between 150.00 and 200.00) towards (Random angle) degrees)
                  • Set TreeChance = (Random integer number between 1 and 100)
                • If (TreeChance Greater than 35) then do (Destructible - Create a BiomeType[C] at LastLocation facing (Random angle) with scale (Random real number between 0.80 and 1.20) and variation (Random integer number between 0 and 9)) else do (Do nothing)
                • Environment - Change terrain type at LastLocation to TerrainType1[C] using variation -1 in an area of size (Random integer number between 2 and 5) and shape Circle
                • Environment - Change terrain type at LastLocation to TerrainType2[C] using variation -1 in an area of size (Random integer number between 2 and 4) and shape Circle
  • Custom script: call RemoveLocation (udg_LastLocation)
  • Custom script: call RemoveLocation (udg_RandomLocation)
 

Attachments

  • 2.JPG
    2.JPG
    171 KB · Views: 73
  • 1.JPG
    1.JPG
    169.6 KB · Views: 105
Level 5
Joined
May 2, 2015
Messages
109
I don't know my sugestions will help, I think,
  • instead using Map initialization, use Elasped game time is 0.01 second.
  • try to convert the GUI code to JASS and check how the loop works
Btw, I don't know how your code actually looks like but from the code you given, it has leaks.
 
Try to put a "Wait 0 seconds" action in the outer loop, with Integer C. So you will reset the operation count 6x, maybe it' senough.

Ensure that Integer A, B, and C are not used elsewhere meanwhile this duration. Because of the "wait 0 seconds" action, other trigger could possibly run in between and manipulate their values.
If you can't ensure it, create 3 new loop integer variables which you only use for this task.

Removing points only in the end of the trigger is not enough, as you overwrite them each time in your loop.
Read Technique Of Removal chapter here: Memory Leaks
 
Level 14
Joined
Dec 24, 2008
Messages
2,126
Thanks, that worked.
As I feared though, the mix of all these biomes spawning randomly and intersecting with each other had some... wacky results.

Any ideas to ensure that the random coordinate points where each starting tree spawns is distanced away from each other?

%C2%A0-jpg.251721
 

Attachments

  •  .JPG
     .JPG
    169 KB · Views: 216
Level 24
Joined
Aug 1, 2013
Messages
4,657
You wanted it to be random, here you have it.

Here is a link for something that you could use to create proper biomes: Voronoi diagram - Wikipedia
However, it doesnt take into account that certain biomes do not fit next to each other.
For example, how would you feel if a snow biome is next to a desert biome?

On the internet, there will be plenty of tutorials on how to make on in general.
You then only have to apply those algorithms in Wc3.
 
Level 7
Joined
Oct 19, 2015
Messages
286
It is fairly simple. You pick some random points on your map that will represent the centres of various biomes, and store them in an array. Then, when you pick a location for a tree, you loop through the biome points to find the nearest one, and create a matching tree.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
in that case, you should consider having a slightly better approach of "random" points
random points are random, so you could very well have 3 biomes surrounding another one so close that the fourth only has 1 tile... or even less.
 
Level 14
Joined
Dec 24, 2008
Messages
2,126
Exactly, I understand that the Voronoi diagram is based on setting random points across the map, and later merge them into polygons, but the thing is that I have to make a condition somehow that these points distance with each other, sort of like with my trees, but also that it covers the entire map.

I can't quite grasp it in my head the way to achieve that due to my limited logical knowledge, since I couldn't quite follow voronoi's formula.
 
Level 7
Joined
Oct 19, 2015
Messages
286
You don't really have to follow some complex formula, though, just when placing a tree find the nearest biome point and plant a tree that matches it. You could then further upgrade this to get more fuzzy borders between biomes by also considering the second closest biome point and if distance to it is within a certain range of the shortest distance then choose randomly between the two biomes which tree to place.
 
Status
Not open for further replies.
Top