HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Memory Leaks.. Gotta love them

08-17-2005, 12:48 AM#1
Tim.
Alright, I got a few leaks here, someone mind pointing them out and telling me how to clean them up please?

Creates Bullets
Quote:
Shoot
Events
Unit - A unit Is issued an order targeting a point
Unit - A unit Is issued an order targeting an object
Conditions
Or - Any (Conditions) are true
Conditions
(Issued order) Equal to (Order(smart))
(Issued order) Equal to (Order(attack))
Actions
-------- Debug --------
Game - Display to (All players) the text: Weapon Shot
-------- This prepares some temp values --------
Set tempPoint = (Target point of issued order)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(X of tempPoint) Equal to (X of (Center of (Entire map)))
(Y of tempPoint) Equal to (Y of (Center of (Entire map)))
Then - Actions
Set tempPoint = (Position of (Target unit of issued order))
Else - Actions
Set tempPoint = (Target point of issued order)
Set BulletDirection[(Player number of (Owner of (Triggering unit)))] = (Angle from (Position of Hero[(Player number of (Owner of (Triggering unit)))]) to tempPoint)
-------- This creates the bullet that will be moved seperately --------
Unit - Create 1 Bullet for (Owner of (Ordered unit)) at (Position of Hero[(Player number of (Owner of (Ordered unit)))]) facing BulletDirection[(Player number of (Owner of (Ordered unit)))] degrees
-------- Custom Value becomes the range of the bullet --------
Unit - Set the custom value of (Last created unit) to 100
Moves Bullets
Quote:
Move Bullets
Events
Time - Every 0.03 seconds of game time
Conditions
Actions
-------- Picks every unit in the game --------
Set BulletGroup = (Units of type Bullet)
Unit Group - Pick every unit in BulletGroup and do (Actions)
Loop - Actions
-------- Moves every bullet forward by a value of 20 --------
Unit - Move (Picked unit) instantly to ((Position of (Picked unit)) offset by 20.00 towards (Facing of (Picked unit)) degrees)
-------- Lowers the Custom Value of the bullet, making it closer to the end of it's range --------
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 1)
-------- Checks if the bullet finished it's range --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Custom value of (Picked unit)) Less than or equal to 0
Then - Actions
Unit - Remove (Picked unit) from the game
Else - Actions
-------- Checks if the bullet hit somthing --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units within 40.00 of (Position of (Picked unit)) matching (((Unit-type of (Matching unit)) Not equal to Footman) and ((Unit-type of (Matching unit)) Not equal to Blood Mage)))) Greater than 0
Then - Actions
-------- Debug --------
Game - Display to (All players) the text: Weapon Hits
-------- Sets the Unit that is to be damaged --------
Set tempDmgUnit = (Random unit from (Units within 40.00 of (Position of (Picked unit))))
-------- Deals a random ammount of damage to the Unit --------
Unit - Set life of tempDmgUnit to ((Life of tempDmgUnit) - (Random real number between 7.00 and 13.00))
-------- Removes the Bullet --------
Unit - Remove (Picked unit) from the game
-------- Clears the tempUnit --------
Set tempDmgUnit = No unit
Else - Actions
08-17-2005, 09:05 AM#2
Anitarf
Quote:
Originally Posted by Tim.
Alright, I got a few leaks here, someone mind pointing them out and telling me how to clean them up please?

Creates Bullets
Quote:
Shoot
Events
Unit - A unit Is issued an order targeting a point
Unit - A unit Is issued an order targeting an object
Conditions
Or - Any (Conditions) are true
Conditions
(Issued order) Equal to (Order(smart))
(Issued order) Equal to (Order(attack))
Actions
-------- Debug --------
Game - Display to (All players) the text: Weapon Shot
-------- This prepares some temp values --------
Set tempPoint = (Target point of issued order)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(X of tempPoint) Equal to (X of (Center of (Entire map)))//center of (region) is a function that creates a point object, and thus it leaks. Just use 0.00 instead?
(Y of tempPoint) Equal to (Y of (Center of (Entire map)))//same as above
Then - Actions
custom script: call RemoveLocation( udg_tempPoint )
Set tempPoint = (Position of (Target unit of issued order))
Else - Actions
Set tempPoint = (Target point of issued order)//this is not needed, and it leaks the point object previously stored in the variable
Set BulletDirection[(Player number of (Owner of (Triggering unit)))] = (Angle from (Position of Hero[(Player number of (Owner of (Triggering unit)))]) //this creates a point object that leaks, store this to a variable first and use the variable in this line to tempPoint)
-------- This creates the bullet that will be moved seperately --------
Unit - Create 1 Bullet for (Owner of (Ordered unit)) at (Position of Hero[(Player number of (Owner of (Ordered unit)))]) //same as before facing BulletDirection[(Player number of (Owner of (Ordered unit)))] degrees //there's an action "create units facing point", if you used that you wouldn't need to calculate BulletDirection
-------- Custom Value becomes the range of the bullet --------
Unit - Set the custom value of (Last created unit) to 100
-------- Clear all temp location objects created by the trigger --------
custom script: call RemoveLocation( udg_tempPoint )
//repeat for any other location you use

Moves Bullets
Quote:
Move Bullets
Events
Time - Every 0.03 seconds of game timeok, now this is a seriously critical trigger
Conditions
Actions
-------- Picks every unit in the game --------
Set BulletGroup = (Units of type Bullet)
Unit Group - Pick every unit in BulletGroup and do (Actions)
Loop - Actions
-------- Moves every bullet forward by a value of 20 --------
Unit - Move (Picked unit) instantly to ((Position of (Picked unit)) offset by 20.00 towards (Facing of (Picked unit)) degrees) //now here you leak two location objects, one is the position of picked unit and another one is when you offset it
-------- Lowers the Custom Value of the bullet, making it closer to the end of it's range --------
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 1)
-------- Checks if the bullet finished it's range --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Custom value of (Picked unit)) Less than or equal to 0
Then - Actions
Unit - Remove (Picked unit) from the game
Else - Actions
-------- Checks if the bullet hit somthing --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units within 40.00 of (Position of (Picked unit)) matching (((Unit-type of (Matching unit)) Not equal to Footman) and ((Unit-type of (Matching unit)) Not equal to Blood Mage)))) //unit group leak Greater than 0
Then - Actions
-------- Debug --------
Game - Display to (All players) the text: Weapon Hits
-------- Sets the Unit that is to be damaged --------
Set tempDmgUnit = (Random unit from (Units within 40.00 of (Position of (Picked unit))) //leak again)
-------- Deals a random ammount of damage to the Unit --------
Unit - Set life of tempDmgUnit to ((Life of tempDmgUnit) - (Random real number between 7.00 and 13.00)) //just a suggestion, use damage triggers instead
-------- Removes the Bullet --------
Unit - Remove (Picked unit) from the game
-------- Clears the tempUnit --------
Set tempDmgUnit = No unit
Else - Actions
-------- Clear all temp objects created by the trigger --------
custom script: call DestroyGroup( udg_BulletGroup )
//repeat for any other location and group you use

08-17-2005, 09:45 AM#3
Tim.
Great. Thanks a lot as always Anitarf.
08-17-2005, 09:31 PM#4
oNdizZ
Anitarf forgot the force leaks.

Game - Display to (All players) the text: Weapon Shot

All players leaks.

if you want, you can just add a new global named AllPlayers then at map ini
set AllPlayers = (All players)
and at end use
call DestroyForce(udg_AllPlayers)

Edit: ohh, nvm, didn't notice that they only were debug msgs. tt