- Joined
- Feb 6, 2014
- Messages
- 2,466
Which is better? qwerty1 or qwerty2?
EDIT: By better, I meant faster. qwerty2 seems slower because it will pick all units and evaluate if it is an enemy but I'm not sure because I don't know how group filter works. Also, does the Filter(code) leak?
EDIT: By better, I meant faster. qwerty2 seems slower because it will pick all units and evaluate if it is an enemy but I'm not sure because I don't know how group filter works. Also, does the Filter(code) leak?
JASS:
scope qwerty1 initializer OnInit
globals
private player filterPlayer
endglobals
private function FilterUnits takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), filterPlayer)
endfunction
private function Cast takes nothing returns nothing
local player p = GetTriggerPlayer()
local unit u
local group g = CreateGroup()
set filterPlayer = p
call GroupEnumUnitsInRange(g, 0, 0, 1500, Filter(function FilterUnits))
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
//do actions here
call KillUnit(u)
call PingMinimap(GetUnitX(u), GetUnitY(u), 1.)
endloop
call DestroyGroup(g)
set p = null
set g = null
endfunction
private function OnInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), "qwerty1", true)
call TriggerAddAction(t, function Cast)
endfunction
endscope
scope qwerty2 initializer OnInit
private function FilterUnits takes unit u, player p returns boolean
return IsUnitEnemy(u, p)
endfunction
private function Cast takes nothing returns nothing
local player p = GetTriggerPlayer()
local unit u
local group g = CreateGroup()
call GroupEnumUnitsInRange(g, 0, 0, 1500, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
if FilterUnits(u,p) then
//do actions here
call KillUnit(u)
call PingMinimap(GetUnitX(u), GetUnitY(u), 1.)
endif
endloop
call DestroyGroup(g)
set p = null
set g = null
endfunction
private function OnInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), "qwerty2", true)
call TriggerAddAction(t, function Cast)
endfunction
endscope
Last edited: