Status
Not open for further replies.

#### MasterDragons

Level 8
I was devoloping a system where grass grows up through tiers of different tiles.
(Ex: Short Grass -> Grassy Dirt -> Grass -> Lumpy Grass -> Vines)
Once it gets to Grass however it Spreads Short grass into the tiles around it, then those tiles eventually grow taller and spread to those around them.

My Problem is that I seem to be using too many for loops within each other and the game decides its an infinity loop and stops the execution.
I know this because if I reduce some of the loops it works, for the most part, just fine.

I was wondering If somebody could either tell me a way to fix my code to make it work better.

Heres My code:

Grass
Events
Time - Every 2.00 seconds of game time
Conditions
Actions
For each (Integer TempIntA) from 1 to 51, do (Actions)
Loop - Actions
For each (Integer TempIntB) from 1 to 51, do (Actions)
Loop - Actions
Set TempLoc = (Load TempIntA of TempIntB in Locations)
For each (Integer TempIntC) from 5 to 7, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempLoc) Equal to GrassLevels[TempIntC]
Then - Actions
Set TempPoint = (TempLoc offset by (128.00, 0.00))
For each (Integer TempIntC) from 4 to 7, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Ashenvale - Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Village - Short Grass using variation -1 in an area of size 1 and shape Circle
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Dalaran - Rough Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Ashenvale - Dirt using variation -1 in an area of size 1 and shape Circle
Else - Actions
Custom script: call RemoveLocation(udg_TempPoint)
Set TempPoint = (TempLoc offset by (-128.00, 0.00))
For each (Integer TempIntC) from 4 to 7, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Ashenvale - Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Village - Short Grass using variation -1 in an area of size 1 and shape Circle
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Dalaran - Rough Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Ashenvale - Dirt using variation -1 in an area of size 1 and shape Circle
Else - Actions
Custom script: call RemoveLocation(udg_TempPoint)
Set TempPoint = (TempLoc offset by (0.00, 128.00))
For each (Integer TempIntC) from 4 to 7, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Ashenvale - Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Village - Short Grass using variation -1 in an area of size 1 and shape Circle
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Dalaran - Rough Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Ashenvale - Dirt using variation -1 in an area of size 1 and shape Circle
Else - Actions
Custom script: call RemoveLocation(udg_TempPoint)
Set TempPoint = (TempLoc offset by (0.00, -128.00))
For each (Integer TempIntC) from 4 to 7, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Ashenvale - Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Village - Short Grass using variation -1 in an area of size 1 and shape Circle
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempPoint) Equal to Dalaran - Rough Dirt
Then - Actions
Environment - Change terrain type at TempPoint to Ashenvale - Dirt using variation -1 in an area of size 1 and shape Circle
Else - Actions
Custom script: call RemoveLocation(udg_TempPoint)
Else - Actions
-------- Grow --------
For each (Integer TempIntC) from 3 to 6, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Terrain type at TempLoc) Equal to GrassLevels[TempIntC]
TempBool Equal to False
Then - Actions
Environment - Change terrain type at TempLoc to GrassLevels[(TempIntC + 1)] using variation -1 in an area of size 1 and shape Circle
Set TempBool = True
Else - Actions
Set TempBool = False
Custom script: call RemoveLocation(udg_TempLoc)

[/trigger]
[trigger=Initialization]
Melee Initialization
Events
Map initialization
Conditions
Actions
Visibility - Disable fog of war
Set GrassLevels[0] = Ashenvale - Rock
Set GrassLevels[1] = Dalaran - Rough Dirt
Set GrassLevels[2] = Ashenvale - Dirt
Set GrassLevels[3] = Village - Short Grass
Set GrassLevels[4] = Ashenvale - Grassy Dirt
Set GrassLevels[5] = Ashenvale - Grass
Set GrassLevels[6] = Ashenvale - Lumpy Grass
Set GrassLevels[7] = Ashenvale - Vines
Hashtable - Create a hashtable
Set Locations = (Last created hashtable)
For each (Integer TempIntA) from 1 to 51, do (Actions)
Loop - Actions
For each (Integer TempIntB) from 1 to 51, do (Actions)
Loop - Actions
Set TempRealA = ((Real((TempIntA - 27))) x 128.00)
Set TempRealB = ((Real((TempIntB - 27))) x 128.00)
Hashtable - Save Handle Of(Point(TempRealA, TempRealB)) as TempIntA of TempIntB in Locations

[/trigger]

Any and all Help Appreciated, If you have any questions just ask.

P.S: I'm pretty sure I got all the leaks, but Im not positive. I figure getting rid of leaks could solve the problem.

Last edited:

#### Assassins-Creed

Level 11
I'm not really sure what the problem is,but I dont think loops stack ontop of each other.

#### MasterDragons

Level 8
I said that I already tried it with smaller loops. They do Work, I've Used them multiple Times before. Thanks anyways, atleast you cared. It seems all of my posts seem to go unanswered while everybody else gets replies almost immediately.

#### rysnt11

Level 17
I said that I already tried it with smaller loops. They do Work, I've Used them multiple Times before. Thanks anyways, atleast you cared. It seems all of my posts seem to go unanswered while everybody else gets replies almost immediately.
just one question, why did you use neg values?, use the normal values might work, like from -26 to 26, why didn't use from 0 to 51?, also attach a map, so everyone can test it, and send the map back to you

#### MasterDragons

Level 8
I used negative values becuase:
A) They Work
B) Why the hell would I not?
C) Warcraft uses Positive & negative values for coordinates and coordinates is exactly why that gets used in the first place.

Just three questions for you:
1) Why'd you quote me? seems pointless.
2) If you werent going to help at all then why post? At least assassin was being helpful.
3) I gave you my code. Thats the only thing in my map. What else are you looking for exactly?

Edit: I ended up changing anyways because I'm not sure if you can put negative values in hashtables.
However, it still doesn't work. So I still think its a performance issue.

Last edited:

#### rysnt11

Level 17
Well, i'm trying to help, okay,so, after you change the values to normal one, it still doesn't work?

#### MasterDragons

Level 8
I thought I made that fairly clear...Obviusly I didn't do a good enough job...
Yes, It did not work.
Thank you regardless. I apologize for being rude, I'am Edgy.

#### rysnt11

Level 17
Nah, don't mind it m8, hmm..., the triggers looks ok, ==a, i can't examine the triggers in the forum... (have bad sight in the forum)

#### MasterDragons

Level 8
Im about 90% sure my Problem is that the trigger is reaching its operation limit due to the fact that it runs some of those if's about 30k times. Im reducing map size to limit the size of the Loops.

If anyone thinks differently and has a solutuion to my problem Please PM Me.
-Unsubscribed-

#### Maker

Level 37
One way to reduce the number of loops is to use GetTerrainTypeId() function and then load the next "tier" from a hashtable using that id as a key. Initialize all tiers by saving integers into the hashtable. That will greatly reduce the loop count.

Status
Not open for further replies.

Replies
4
Views
638
[Trigger] Shorter Trigger
Replies
4
Views
959
[Trigger] Changin Terrain
Replies
24
Views
1K
D
Replies
3
Views
1K
Deleted member 177737
D
Replies
8
Views
671