• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

CAN'T Find an infinite loop

Status
Not open for further replies.

sentrywiz

S

sentrywiz

My map crashes every minute or so when I play it because there might be an infinite loop in my triggers that I can't find it.

Triggers are for an AI:


  • CPU HQ
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Game - Display to (All players) for 0.50 seconds the text: |cffcccccc<order lo...
      • Set CPU_MainUnitGroup = (Units owned by Player 2 (Blue) matching (((Matching unit) is A structure) Not equal to True))
      • If ((Number of units in CPU_MainUnitGroup) Less than or equal to 9) then do (Trigger - Run CPU BUILD <gen> (ignoring conditions)) else do (Do nothing)
      • Unit Group - Pick every unit in CPU_MainUnitGroup and do (Actions)
        • Loop - Actions
          • Trigger - Run CPU UNIT HEALED <gen> (ignoring conditions)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Percentage life of (Picked unit)) Less than or equal to 50.00
              • Or - Any (Conditions) are true
                • Conditions
                  • (Custom value of (Picked unit)) Equal to 0
                  • (Custom value of (Picked unit)) Equal to 2
                  • (Custom value of (Picked unit)) Equal to 3
                  • (Custom value of (Picked unit)) Equal to 4
            • Then - Actions
              • Game - Display to (All players) the text: heal
              • Unit - Set the custom value of (Picked unit) to 1
              • Trigger - Run CPU ESCAPE <gen> (ignoring conditions)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Engineer
                  • (Custom value of (Picked unit)) Not equal to 2
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (CPU CAPTURE PUMP <gen> is on) Equal to True
                      • (CPU CAPTURE LAB <gen> is on) Equal to True
                      • (CPU CAPTURE PALACE <gen> is on) Equal to True
                • Then - Actions
                  • Game - Display to (All players) the text: capture n
                  • Trigger - Run CPU CAPTURE N <gen> (ignoring conditions)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of (Picked unit)) Equal to Centurion
                    • Then - Actions
                      • Game - Display to (All players) the text: centurion def
                      • Unit - Set the custom value of (Picked unit) to 4
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of (Picked unit)) Equal to Raider
                        • Then - Actions
                          • Game - Display to (All players) the text: raider go
                          • Unit - Set the custom value of (Picked unit) to 2
                          • Trigger - Run CPU CAPTURE E <gen> (ignoring conditions)
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Unit-type of (Picked unit)) Equal to Disruptor
                            • Then - Actions
                              • Game - Display to (All players) the text: disruptor go
                              • Unit - Set the custom value of (Picked unit) to 4
                            • Else - Actions
      • Custom script: call DestroyGroup ( udg_CPU_MainUnitGroup )



  • CPU CAPTURE N
    • Events
    • Conditions
    • Actions
      • Set CPU_Pumps = (Units owned by Player 2 (Blue) of type Pump Station)
      • Set CPU_Labs = (Units owned by Player 2 (Blue) of type Research Lab)
      • Set CPU_Palaces = (Units owned by Player 2 (Blue) of type Goblin Palace)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in CPU_Pumps) Less than 4
          • (Custom value of (Picked unit)) Not equal to 1
          • (Custom value of (Picked unit)) Not equal to 2
        • Then - Actions
          • If ((CPU CAPTURE PUMP <gen> is on) Not equal to True) then do (Trigger - Turn on CPU CAPTURE PUMP <gen>) else do (Do nothing)
          • Unit - Set the custom value of (Picked unit) to 2
          • Trigger - Run CPU CAPTURE PUMP <gen> (ignoring conditions)
          • Unit - Order (Picked unit) to Human Dragonhawk Rider - Aerial Shackles CPU_CaptureUnit
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in CPU_Labs) Less than 1
              • (Custom value of (Picked unit)) Not equal to 1
              • (Custom value of (Picked unit)) Not equal to 2
            • Then - Actions
              • If ((CPU CAPTURE PUMP <gen> is on) Equal to True) then do (Trigger - Turn off CPU CAPTURE PUMP <gen>) else do (Do nothing)
              • If ((CPU CAPTURE LAB <gen> is on) Not equal to True) then do (Trigger - Turn on CPU CAPTURE LAB <gen>) else do (Do nothing)
              • Unit - Set the custom value of (Picked unit) to 2
              • Trigger - Run CPU CAPTURE LAB <gen> (ignoring conditions)
              • Unit - Order (Picked unit) to Human Dragonhawk Rider - Aerial Shackles CPU_CaptureUnit
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in CPU_Palaces) Less than 1
                  • (Custom value of (Picked unit)) Not equal to 1
                  • (Custom value of (Picked unit)) Not equal to 2
                • Then - Actions
                  • If ((CPU CAPTURE PUMP <gen> is on) Equal to True) then do (Trigger - Turn off CPU CAPTURE PUMP <gen>) else do (Do nothing)
                  • If ((CPU CAPTURE PALACE <gen> is on) Equal to True) then do (Trigger - Turn off CPU CAPTURE LAB <gen>) else do (Do nothing)
                  • If ((CPU CAPTURE PALACE <gen> is on) Not equal to True) then do (Trigger - Turn on CPU CAPTURE PALACE <gen>) else do (Do nothing)
                  • Unit - Set the custom value of (Picked unit) to 2
                  • Trigger - Run CPU CAPTURE PALACE <gen> (ignoring conditions)
                  • Unit - Order (Picked unit) to Human Dragonhawk Rider - Aerial Shackles CPU_CaptureUnit
                • Else - Actions
                  • If ((CPU CAPTURE PUMP <gen> is on) Equal to True) then do (Trigger - Turn off CPU CAPTURE PUMP <gen>) else do (Do nothing)
                  • If ((CPU CAPTURE PALACE <gen> is on) Equal to True) then do (Trigger - Turn off CPU CAPTURE LAB <gen>) else do (Do nothing)
                  • If ((CPU CAPTURE PALACE <gen> is on) Equal to True) then do (Trigger - Turn on CPU CAPTURE PALACE <gen>) else do (Do nothing)
      • Custom script: call DestroyGroup ( udg_CPU_Pumps )
      • Custom script: call DestroyGroup ( udg_CPU_Labs )
      • Custom script: call DestroyGroup ( udg_CPU_Palaces )



  • CPU CAPTURE PUMP
    • Events
    • Conditions
    • Actions
      • Set CPU_Loc3 = (Position of (Picked unit))
      • Set CPU_EngineerGroup = (Units owned by Neutral Passive matching ((Unit-type of (Matching unit)) Equal to Pump Station))
      • Set CPU_RandomCapture = (Random unit from CPU_EngineerGroup)
      • Set CPU_Loc4 = (Position of CPU_RandomCapture)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between CPU_Loc3 and CPU_Loc4) Greater than 1000.00
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between CPU_Loc3 and CPU_Loc4) Greater than 2000.00
            • Then - Actions
              • Trigger - Run (This trigger) (ignoring conditions)
            • Else - Actions
              • Set CPU_CaptureUnit = CPU_RandomCapture
              • Trigger - Turn off (This trigger)
        • Else - Actions
          • Set CPU_CaptureUnit = CPU_RandomCapture
      • Custom script: call DestroyGroup ( udg_CPU_EngineerGroup )
      • Custom script: call RemoveLocation ( udg_CPU_Loc4 )
      • Custom script: call RemoveLocation ( udg_CPU_Loc3 )


My money is on the capture trigger that is issued a run being called a bazillion times at one point.
It does run smoothly until the AI captures 4 buildings. Usually when the capture lab trigger is supposed to run,
this is where a crash occurs. But there is no error or anything, just WC3 exiting.

There are two other triggers, 1 for capturing labs other for capturing palaces but it doesn't matter,
both of them are copies of the CPU CAPTURE PUMP trigger with changed vars.

+REP and smart points for solution.

EDIT

+rep to IcemanBo for pointing me in the right direction. It was an infinite loop connected not to the first trigger but to the second since distance was always greater than 2000 and it run endless number of times.

Thread can be closed.
 
Last edited by a moderator:
In "CPU CAPTURE PUMP" and in "CPU CAPTURE N" trigger you use "picked unit".
Only use picked unit if you use "Pick Every Unit And Do Actions" before.

Edit: So you if you use "position of picked unit" it will bug because you dont have a unit picked. (in CPU CAPTURE PUMP)

Then distance is maybe always larger than 2000 --> infinite loop
 

sentrywiz

S

sentrywiz

In "CPU CAPTURE PUMP" and in "CPU CAPTURE N" trigger you use "picked unit".
Only use picked unit if you use "Pick Every Unit And Do Actions" before.

Edit: So you if you use "position of picked unit" it will bug because you dont have a unit picked. (in CPU CAPTURE PUMP)

Then distance is maybe always larger than 2000 --> infinite loop

In CPU HQ I pick every unit in group every .5 or .25 seconds (set to .5 for testing)

There is a picked unit because every trigger is a run trigger on the trigger beforehand. I don't pick units anywhere else rather than in CPU HQ.

EDIT:

I just tested. I pick units correctly.
That's not it.
 

sentrywiz

S

sentrywiz

If you run another trigger you can't use picked unit anymore. You have to put your unit into a global variable and use it as refrenrece in further actions.

Not true.

I think you are missing the point of the trigger.
Main trigger runs .25 seconds.
It checks for stuff.
It runs the capture N trigger.
Capture N runs the capture pump trigger.
Capture pump runs itself if distance is greater than 2000.

I never left the main trigger. It constantly loops and checks. So it constantly picking all units owned by player 2. There is always a valid picked unit.

Here read about it if you think otherwise:

http://www.hiveworkshop.com/forums/triggers-scripts-269/temporary-variables-using-run-trigger-action-within-loop-212437/
 

sentrywiz

S

sentrywiz

The trigger goes like this:

(Generate Random Unit)
IF Distance between Picked and Random Unit greater than 1000
THEN CHECK
IF Distance between Picked and Random Unit greater than 2000
RUN TRIGGER AGAIN (Generating another random unit)
ELSE Distance Not Greater Than 1000 Set Variable
ELSE Distance Not Greater Than 2000 Set Variable

I only run the trigger so it randomly selects another unit.
Its not infinite loop because it runs until a random unit found
is not greater than 1000 or 2000.
 
The trigger goes like this:

(Generate Random Unit)
IF Distance between Picked and Random Unit greater than 1000
THEN CHECK
IF Distance between Picked and Random Unit greater than 2000
RUN TRIGGER AGAIN (Generating another random unit)
ELSE Distance Not Greater Than 1000 Set Variable
ELSE Distance Not Greater Than 2000 Set Variable

I only run the trigger so it randomly selects another unit.
Its not infinite loop because it runs until a random unit found
is not greater than 1000 or 2000.

And what if distance is always more than 2000? ---> infinite loop
 

sentrywiz

S

sentrywiz

And what if distance is always more than 2000? ---> infinite loop

Its not infinite loop. That's the first thing I did -> I added a game message displaying number of times trigger runs.

Sometimes it was once, sometimes it was 10 sometimes it was 3.

I already tested against this
It may be an infinite loop if every run trigger runs itself again and again and again. Yes that is an infinite loop, but in my testing that never happened
and the game always crashed out of something.
 
It would help if you completely narrow down the trigger that is the cause. To do this simply turn off some triggers until you find the culprit. Then post that trigger here.
Also you should learn how to make your triggers more efficient. Anything used twice or more should be stored into a temp variable and the variable should be used. Example: custom value of picked unit should be stored before the ITE
 
Status
Not open for further replies.
Top