- Joined
- Mar 9, 2008
- Messages
- 161
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:
[trigger=Spread]
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)
-------- Spread --------
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
-------- RightSpread --------
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)
-------- LeftSpread --------
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)
-------- UpSpread --------
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)
-------- DownSpread --------
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
Visibility - Disable black mask
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.
(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:
[trigger=Spread]
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)
-------- Spread --------
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
-------- RightSpread --------
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)
-------- LeftSpread --------
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)
-------- UpSpread --------
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)
-------- DownSpread --------
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
Visibility - Disable black mask
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: