• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Spreading Grass

Status
Not open for further replies.
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.
 
Last edited:
Level 17
Joined
Jan 21, 2010
Messages
2,111
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
 
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:
Status
Not open for further replies.

Similar threads

Top