Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
local integer i = 0
local group g = CreateGroup()
local real x = ...
local real y = ...
loop
exitwhen i == 1000
call GroupEnumUnitsInRange(g, 500, x, y, null)
call ForGroup(g, function ...)
call ClearGroup(g)
set i = i + 1
endloop
local integer i = 0
local real x = ...
local real y = ...
loop
exitwhen i == 1000
local group g = CreateGroup()
call GroupEnumUnitsInRange(g, 500, x, y, null)
call ForGroup(g, function ...)
call DestroyGroup(g)
set i = i + 1
endloop
Well, sometimes people prefer using the same handle 1000 times rather than creating 1000 handles.
JASS:local integer i = 0 local group g = CreateGroup() local real x = ... local real y = ... loop exitwhen i == 1000 call GroupEnumUnitsInRange(g, 500, x, y, null) call ForGroup(g, function ...) call ClearGroup(g) set i = i + 1 endloop
Instead of:
JASS:local integer i = 0 local real x = ... local real y = ... loop exitwhen i == 1000 local group g = CreateGroup() call GroupEnumUnitsInRange(g, 500, x, y, null) call ForGroup(g, function ...) call DestroyGroup(g) set i = i + 1 endloop
Use a simlar JASS script to that of the timer recycler.
Basically when you get the contence of a group via the native for a trigger like an AoE of a spell it cleans out the contence of the group and replaces it with new contence.
This means that the same group object would not need to be destroyed as it could be reused infinatly. This removes any chance of leaks occuring and also makes the trigger more efficent as it constantly is not having to allocate a group and then deallocate it. This method can be extreemly useful in cases where you need to get units on the map via something like the get units in range etc for a spell a lot of times a second. Also if I am not mistaken, you can initialize globals with a handle value but only in JNGP as that enables one to have better controle over globals.
scope ASpell
private struct TheStruct
//stuff in the struct
endstruct
globals
private TheStruct array darr
private integer max
private timer T = CreateTimer()
endglobals
private function Loop takes nothing returns nothing
local integer i = 0
local TheStruct dat
loop
exitwhen i == max
set dat = darr[i]
//do stuff
if <deallocate> then
set max = max - 1
set darr[i] = darr[max]
if max == 0 then
call PauseTimer(T)
endif
else
set i = i + 1
endif
endloop
endfunction
private function Actions takes nothing returns nothing
local TheStruct dat = TheStruct.create()
//initialize the struct
set darr[max] = dat
if max == 0 then
call TimerStart(T,<interval>,true,function Loop)
endif
set max = max + 1
endfunction
endscope
globals
// User-defined
abilcode udg_ab
attacktype udg_at = null
boolean udg_bo = false
buffcode udg_bu
camerasetup udg_ca = null
gamespeed udg_gam = null
integer udg_in = 0
item udg_it = null
itemtype udg_ite = null
integer udg_item = 0
leaderboard udg_le = null
lightning udg_li = null
lightningtype udg_lig = null
weapontype udg_co = null
damagetype udg_da = null
destructable udg_de = null
destructablecode udg_des
defeatcondition udg_def = null
dialog udg_di = null
button udg_dia = null
effecttype udg_ef = null
texttag udg_fl = null
gamecache udg_ga = null
image udg_im = null
imagetype udg_ima = null
multiboard udg_Mu = null
pathingtype udg_pa = null
quest udg_qu = null
questitem udg_que = null
race udg_ra = null
real udg_re = 0
rect udg_rec = null
sound udg_so = null
effect udg_sou = null
integer udg_or = 0
player udg_pl = null
playercolor udg_pla = null
force udg_play = null
location udg_po = null
string udg_st
integer udg_te = 0
terraindeformation udg_ter = null
integer udg_terr = 0
integer udg_terra = 0
timer udg_ti = null
timerdialog udg_tim = null
trigger udg_tr = null
ubersplat udg_ub = null
string udg_ube
unit udg_un = null
group udg_uni = null
fogmodifier udg_vi = null
weathereffect udg_we = null
// Generated
trigger gg_trg_Melee_Initialization = null
trigger gg_trg_Test = null
a
endglobals
Contrary to popular belief, the best known current way uses neither.
JASS:scope ASpell private struct TheStruct //stuff in the struct endstruct globals private TheStruct array darr private integer max private timer T = CreateTimer() endglobals private function Loop takes nothing returns nothing local integer i = 0 local TheStruct dat loop exitwhen i == max set dat = darr[i] //do stuff //WHEN YOU WANT TO DEALLOCATE set max = max - 1 set darr[i] = darr[max] if max == 0 then call PauseTimer(T) endif //BACK TO MAIN SPELL set i = i + 1 endloop endfunction private function Actions takes nothing returns nothing local TheStruct dat = TheStruct.create() //initialize the struct set darr[max] = dat if max == 0 then call TimerStart(T,<interval>,true,function Loop) endif set max = max + 1 endfunction endscope
Voila, your spell now uses only one timer and no attachment system to speak of.

max is increased when the timeout is over
Herman said:The only thing I have a small problem with is when you deallocate, you set your max down one, and set the stored struct that has been deallocated to the struct that was the max index struct, so the struct that had the index of the max is not eliminated, it is just moved to the place of the one you did eliminate, decreasing your total max whilst eliminating the appropriate struct
//do stuff just add an if/than/else checking if time is stopped. You have to make this, to suit you. For instance in the projectile struct you can add a boolean to see if the projectile is stopped and in the timer callback see if it is. And/Or you can make a global boolean and check that as well.globals
region lulz
endglobals
Event - Every 4 seconds of time[real]
Condition -
Action -

Create 1 [Beserker] at [spawn region1] facing 270.00 degrees

Order [last created unit] to patrol to [ End Region Orc]

Create 1 [Beserker] at [spawn region1] facing 270.00 degrees

Order [last created unit] to patrol to [ End Region Orc]

Create 1 [Orc Soilder] at [spawn region1] facing 270.00 degrees

Order [last created unit] to patrol to [ End Region Orc]

Create 1 [Orc Soilder] at [spawn region1] facing 270.00 degrees

Order [last created unit] to patrol to [ End Region Orc]

Create 1 [Orc Archer] at [spawn region1] facing 270.00 degrees

Order [last created unit] to patrol to [ End Region Orc]
spawn region1 leaks. Every time you use it.
Seems to me it does not leak. Because spawn region1 is a global variable. So it uses the same memory every time you call it. Does not allocate another memory, so it won't leak.
ORC Rally 1

Events


Time - Every 4.00 seconds of game time

Conditions

Actions


Unit - Create 1 Grunt for Player 12 (Brown) at (Center of ACR 1 <gen>) facing Default building facing degrees


Unit - Order (Last created unit) to Patrol To (Center of End Region 1 <gen>)


Unit - Create 1 Grunt for Player 12 (Brown) at (Center of ACR 1 <gen>) facing Default building facing degrees


Unit - Order (Last created unit) to Patrol To (Center of End Region 1 <gen>)


Unit - Create 1 Troll Headhunter for Player 12 (Brown) at (Center of ACR 1 <gen>) facing Default building facing degrees


Unit - Order (Last created unit) to Patrol To (Center of End Region 1 <gen>)


Unit - Create 1 Troll Headhunter for Player 12 (Brown) at (Center of ACR 1 <gen>) facing Default building facing degrees


Unit - Order (Last created unit) to Patrol To (Center of End Region 1 <gen>)


Unit - Create 1 Grunt for Player 12 (Brown) at (Center of ACR 1 <gen>) facing Default building facing degrees


Unit - Order (Last created unit) to Patrol To (Center of End Region 1 <gen>)
Sagitarius Arrow Movement

Events


Time - Every 0.04 seconds of game time

Conditions

Actions


Set Location3[62] = (Position of Sagitarius_Arrow_Dummy)


Set Location3[63] = (Position of Sagitarius_Arrow_Targ)


If (All Conditions are True) then do (Then Actions) else do (Else Actions)



If - Conditions




(Distance between Location3[62] and Location3[63]) Greater than or equal to 40.00



Then - Actions




Set Location3[65] = (Location3[62] offset by 30.00 towards (Angle from Location3[62] to Location3[63]) degrees)




Unit - Move Sagitarius_Arrow_Dummy instantly to Location3[65]




If (((Current flying height of Sagitarius_Arrow_Dummy) Less than or equal to 300.00) and ((Distance between Location3[62] and Location3[63]) Greater than or equal to 2000.00)) then do (Animation - Change Sagitarius_Arrow_Dummy flying height to ((Current flying height of Sagitarius_Arrow_Dummy) + 100.00) at 200.00) else do (Do nothing)




If (((Current flying height of Sagitarius_Arrow_Dummy) Greater than or equal to 200.00) and ((Distance between Location3[62] and Location3[63]) Less than 2000.00)) then do (Animation - Change Sagitarius_Arrow_Dummy flying height to ((Current flying height of Sagitarius_Arrow_Dummy) - 100.00) at 200.00) else do (Do nothing)




Custom script: call RemoveLocation(udg_Location3[65])



Else - Actions




If (All Conditions are True) then do (Then Actions) else do (Else Actions)





If - Conditions






((Sagitarius_Arrow_Targ is in Spell_Imunity_Group) Not equal to True) and (((Sagitarius_Arrow_Targ is Magic Immune) Not equal to True) and (((Sagitarius_Arrow_Targ is in SleepingGroup) Not equal to True) and (((Sagitarius_Arrow_Targ has buff Eternal Drowsiness ) Not equal to True) and (((Sagitarius_Arrow_Targ has buff Coffin of Ice





Then - Actions






Unit - Grant shared vision of Sagitarius_Arrow_Targ to (Owner of Sagitarius_Arrow_Dummy)






Unit - Order Sagitarius_Arrow_Dummy to Stop






Unit - Order Sagitarius_Arrow_Dummy to Human Mountain King - Storm Bolt Sagitarius_Arrow_Targ






Wait until (Sagitarius_Arrow_Casted Equal to True), checking every 0.10 seconds






Unit - Remove Sagitarius_Arrow_Dummy from the game






Unit - Deny shared vision of Sagitarius_Arrow_Targ to (Owner of Sagitarius_Arrow_Dummy)






Set Sagitarius_Arrow_Casted = False






Trigger - Turn off (This trigger)






Trigger - Turn off Sagitarius Arrow Target DIES <gen>






Trigger - Turn off Sagitarius Arrow Casted True <gen>





Else - Actions






Unit - Kill Sagitarius_Arrow_Dummy






Set Sagitarius_Arrow_Casted = False






Trigger - Turn off (This trigger)






Trigger - Turn off Sagitarius Arrow Target DIES <gen>






Trigger - Turn off Sagitarius Arrow Casted True <gen>


Custom script: call RemoveLocation(udg_Location3[62])


Custom script: call RemoveLocation(udg_Location3[63])
Ok Ralle you wer talkin bout destroying special effects and u used "Special Effect - Destroy (Last created special effect)". Now i see that this would work for any special effect that did not last any time but what if you were to make an event where you wanted the special effect to last for something like 10 seconds. Then if the event happened twice within the 10 seconds it would destroy only the "last created special effect" meaning the first one would just stay there and never disapear. So shouldnt you use an array for that too??? Also say a unit has an ability that makes a special effect at a point and that ability can be cast 2 times within the abilities (and special effects) duration. Would it be possible to destroy both effects even tho they were created by the same unit and owned by the same player and in existence at the same time?
