HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Do these triggers lleak?

02-07-2006, 02:56 PM#1
Uchiha Sasuke
I've read some threads about the specific event called "unit within range" to make it a generic event, and i found out that it ain't that simple to do. However, in my case it shouldn't be that hard since my map is limited in the number of units to which such a trigger applies to.

First we give a number to each tank made by player 1:
Trigger:
Tank scan
Collapse Events
Time - Every 1.00 seconds of game time
Collapse Conditions
(Number of units in (Units owned by Player 1 (Red) of type Tank)) Greater than 0
Collapse Actions
Collapse For each (Integer A) from 0 to 50, do (Actions)
Collapse Loop - Actions
Set var3[(Integer A)] = (Position of var1[(Integer A)])
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Number of units in (Units within (Default acquisition range of var1[(Integer A)]) of var3[(Integer A)] matching ((Owner of (Matching unit)) Equal to Player 2 (Blue)))) Greater than 0
((Matching unit) is alive) Equal to True
Collapse Then - Actions
Unit - Order var1[(Integer A)] to Stop
Unit - Order var1[(Integer A)] to Attack (Matching unit)
Collapse Else - Actions
Do nothing

Then we see if any enemy unit is within range of a tank. Tanks are limited to 20 on each side, so I'll replace the 50 with 25 or something later:
Trigger:
Tank scan
Collapse Events
Time - Every 1.00 seconds of game time
Collapse Conditions
(Number of units in (Units owned by Player 1 (Red) of type Tank)) Greater than 0
Collapse Actions
Collapse For each (Integer A) from 0 to 50, do (Actions)
Collapse Loop - Actions
Set var3[(Integer A)] = (Position of var1[(Integer A)])
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Number of units in (Units within (Default acquisition range of var1[(Integer A)]) of var3[(Integer A)] matching ((Owner of (Matching unit)) Equal to Player 2 (Blue)))) Greater than 0
((Matching unit) is alive) Equal to True
Collapse Then - Actions
Unit - Order var1[(Integer A)] to Stop
Unit - Order var1[(Integer A)] to Attack (Matching unit)
Collapse Else - Actions
Do nothing

The arrays can always be cleared when the unit in it dies, reducing the number of arrays needed.

Trigger:
Tank death
Collapse Events
Unit - A unit owned by Player 1 (Red) Dies
Collapse Conditions
(Owner of (Dying unit)) Equal to Player 1 (Red)
(Unit-type of (Dying unit)) Equal to Tank
Collapse Actions
Collapse For each (Integer A) from 0 to 50, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Dying unit) Equal to var1[(Integer A)]
Collapse Then - Actions
Set var1[(Integer A)] = No unit
Collapse Else - Actions
Do nothing

var2[0] will reach 51, then we can just scan for empty arrays and assign new units to the empty arrays:

Trigger:
Tank control 2
Collapse Events
Unit - A unit Finishes training a unit
Collapse Conditions
(Owner of (Trained unit)) Equal to Player 1 (Red)
(Unit-type of (Trained unit)) Equal to Tank
var2[0] Greater than 50
Collapse Actions
Collapse For each (Integer B) from 0 to 50, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
var1[(Integer B)] Equal to No unit
var4[0] Equal to 0
Collapse Then - Actions
Set var1[(Integer B)] = (Trained unit)
Set var4[0] = 1
Collapse Else - Actions
Do nothing
Set var4[0] = 0

I think this should work for me, i haven't really been able to test it. But here's my question: I use variables almost everywhere and I overwrite them constantly. Does this still leak then?
02-07-2006, 04:06 PM#2
Captain Griffen
Firstly, any creation of a unit group, player group, position, and a few others, will leak. This includes in conditions.

Secondly, variables leak. They are not actually overwritten, but the data remains in the computer, just the variable is re-directed to the new variable setting.

This can be gotten around by setting the unit group to a variable (TempGroup for any ones that are only for an instant), carrying out the action/condition (using if/then/else), and then destroying the variable, before you set the variable to something else. You need to use custom code or JASS to destroy variables, but a good tutorial can be found in the tutorial section.