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
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.
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?