HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

For Loop Limits and Another Related Issue

10-15-2006, 02:18 PM#1
KuBaN
I am trying to change the terrain in a rect when the map starts via triggers. The map is 128 x 256, with two regions that are to be identical in size and shape, so the area of terrain I'm trying to change is a little less than 128 x 128. I do not want to do it manually via the WE, because then I have to limit the amount of tiles I can use. My first attempt looked like this:

Trigger:
Spirit Realm Terrain OLD
Collapse Events
Map initialization
Conditions
Collapse Actions
Visibility - Disable black mask
Visibility - Disable fog of war
Collapse For each (Integer A) from ((Integer((Min X of RealmSpirit <gen>))) / 96) to ((Integer((Max X of RealmSpirit <gen>))) / 96), do (Actions)
Collapse Loop - Actions
Set X = ((Integer A) x 96)
Collapse For each (Integer B) from ((Integer((Min Y of RealmSpirit <gen>))) / 96) to ((Integer((Max Y of RealmSpirit <gen>))) / 96), do (Actions)
Collapse Loop - Actions
Set Y = ((Integer B) x 96)
Set int_TrigCount = (int_TrigCount + 1)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Rough Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Rough Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Grassy Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Light Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Rock) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Flat Stones using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Grass) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Small Bricks using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Dark Grass) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Large Bricks using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
The A For Loop is for the X coord, and the B loop for the Y coord. I have it divide by 96 and then multiply by 96 in order to cut down the loops (it only needs to change the terrain every 96 or so "measurements").

The good thing here is that the terrain changes are done seemingly instantaneously (I'll explain that shortly). The problem, however, is that the loop only seems to run around 1150 times, and to complete the region it would have to run about 24,000. It runs through the A loop only thrice, so there are three vertical lines of the correct terrain, the rest is left unchanged.

So I assumed there was a limit on the amount of times the For Loop can run. I then decided to create a manual for loop.
Trigger:
Init World
Collapse Events
Time - Elapsed game time is 0.05 seconds
Conditions
Collapse Actions
Set X = (Integer((Max X of RealmSpirit <gen>)))
Set Y = (Integer((Max Y of RealmSpirit <gen>)))
Visibility - Disable black mask
Visibility - Disable fog of war
Trigger:
Spirit Realm Terrain
Collapse Events
Time - Elapsed game time is 0.01 seconds
Conditions
Collapse Actions
Wait 0.00 seconds
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
X Greater than (Integer((Min X of RealmSpirit <gen>)))
Y Greater than (Integer((Min Y of RealmSpirit <gen>)))
Collapse Then - Actions
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Rough Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Rough Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Grassy Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Light Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Rock) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Flat Stones using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Grass) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Small Bricks using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Dark Grass) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Large Bricks using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
Set Y = (Y - 96)
Trigger - Run (This trigger) (checking conditions)
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
X Greater than (Integer((Min X of RealmSpirit <gen>)))
Y Less than or equal to (Integer((Min Y of RealmSpirit <gen>)))
Collapse Then - Actions
Set X = (X - 96)
Set Y = (Integer((Max Y of RealmSpirit <gen>)))
Trigger - Run (This trigger) (checking conditions)
Collapse Else - Actions
Game - Display to (All players) the text: TERRAIN-FACE CHANGE COMPLETE

This way, the loop does not unexpectedly end itself. However, the Wait action causes the trigger to delay enough that it would take about five minutes for the entire region to be correctly changed. If I remove the Wait Action, the game crashes the moment this trigger runs. Either way presents a problem. I understand if need be I can just run separate for loops, doing things in sections, but it just seems odd that the loop is limited like that.

I am willing to use either of these triggers if there is a solution to either problem.
10-15-2006, 02:29 PM#2
Vexorian
It doesn't really make any sense, that code. I would say that you need to remake it completelly.

For what I can see, your trigger is an endless loop. Otherwise it wouldn't crash - it would just take some time, I bet there is no way to get to the else action that doesn't use run (this trigger), In fact, after adding the wait, you are just making the endless loop last forever, even after it actually finishes the map.
10-15-2006, 02:41 PM#3
KuBaN
Are you referring to the first or the second?

It isn't endless.
Code:
X = MaxX of Region
Y = MaxY of Region

CHANGE TERRAIN at X,Y
IF (X > MinX of Region && Y > MinY of Region){
    SET Y = Y-1;
    RUN This Trigger;
}
ELSE IF (X > Minx of Region && Y <= MinY of Region){
    SET X = X-1;
    RUN This Trigger;
}
IF
MinX = 0, MaxX = 3
MinY = 0, MaxY = 3

Then it should run through the code, changing the terrain at each coord

3,3
3,2
3,1
3,0

2,3
2,2
2,1
2,0

Until it reaches 0,0 (the MinX and MinY), in which case it will stop.
10-15-2006, 04:33 PM#4
KuBaN
I tested the second method further by adding a trigger counter and telling the Wait only to execute if the trigger has been run less than x amount of times. Once the counter exceeds x, on the next pass, the game crashes. If I relocate the Wait action to the second loop (the one that it passes when X is changed, which happens less frequently than Y), the time it takes to change all of the terrain decreases considerably, but it still must wait after each vertical line of terrain is completed. I let it run all the way through, it completes the terrain, and the loop exits, and all is well, <b>only</b> if there is a Wait action somewhere amongst the loop. Still don't know why, which is my problem.

Edit:

And regarding the first method, I'm guessing there is a limit on the For Loop?
10-15-2006, 05:04 PM#5
KuBaN
Trigger:
Init World
Collapse Events
Time - Elapsed game time is 0.05 seconds
Conditions
Collapse Actions
Set X = (Integer((Max X of RealmSpirit <gen>)))
Set Y = (Integer((Max Y of RealmSpirit <gen>)))
Trigger:
Spirit Realm Terrain
Collapse Events
Time - Elapsed game time is 0.01 seconds
Conditions
Collapse Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
X Greater than (Integer((Min X of RealmSpirit <gen>)))
Y Greater than (Integer((Min Y of RealmSpirit <gen>)))
Collapse Then - Actions
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Rough Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Rough Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Grassy Dirt) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Light Dirt using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Rock) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Flat Stones using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Grass) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Small Bricks using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
If ((Terrain type at (Point((Real(X)), (Real(Y))))) Equal to Lordaeron Summer - Dark Grass) then do (Environment - Change terrain type at (Point((Real(X)), (Real(Y)))) to Black Citadel - Large Bricks using variation -1 in an area of size 1 and shape Circle) else do (Do nothing)
Set Y = (Y - 96)
Trigger - Run (This trigger) (checking conditions)
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
X Greater than (Integer((Min X of RealmSpirit <gen>)))
Y Less than or equal to (Integer((Min Y of RealmSpirit <gen>)))
Collapse Then - Actions
Set X = (X - 96)
Set Y = (Integer((Max Y of RealmSpirit <gen>)))
If ((int_TrigCount mod 9) Equal to 0) then do (Wait 0.01 seconds) else do (Do nothing)
Set int_TrigCount = (int_TrigCount + 1)
Trigger - Run (This trigger) (checking conditions)
Else - Actions

I basically told it to wait every 9th pass. It runs it a lot faster (completes everything in under ten seconds), and doesn't crash. If I run it every 10th pass, it crashses. It will suffice, but I still don't understand why, and that is what I was asking.

And by the way, "Your trigger sucks, redo it" is not a very constructive reply.