Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
Hi it's me again, this time it's a different spell. The actual effect of the spell is not relevant to the question though, so I'll just paste the part of the code I'm having trouble with:
JASS:
function Trig_Forgotten_Flail_Filter takes unit Caster_ForgottenFlail returns boolean
return IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(Caster_ForgottenFlail))
endfunction
function Trig_Forgotten_Flail_Actions takes nothing returns nothing
local unit Caster_ForgottenFlail = GetSpellAbilityUnit()
local unit Random_ForgottenFlail
set Random_ForgottenFlail = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(800.00, GetUnitLoc(Caster_ForgottenFlail), Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail))))
endfunction
The error is : Expected '
at the set Random_ForgottenFlail line. I expect it to be something dumb but I can't see what =(
GetSpellAbilityUnit() (a BJ) == GetTriggerUnit() (a native)
JASS:
local unit Random_ForgottenFlail
set Random_ForgottenFlail = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(800.00, GetUnitLoc(Caster_ForgottenFlail), Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail))))
Is equal to:
JASS:
local unit Random_ForgottenFlail = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(800.00, GetUnitLoc(Caster_ForgottenFlail), Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail))))
You got a leak, you're not destroying GetUnitLoc(Caster_ForgottenFlail), fix it like this:
JASS:
local location Loc = GetUnitLoc(Caster_ForgottenFlail)
local unit Random_ForgottenFlail = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(800.00, Loc, Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail))))
call RemoveLocation(Loc)
But now, GetUnitsInRangeOfLocMatching is a leak, this way is more efficient and it's leak-less:
JASS:
local group g = CreateGroup()
local unit Random_ForgottenFlail
call GroupEnumUnitsInRange(g, GetUnitX(Caster_ForgottenFlail), GetUnitY(Caster_ForgottenFlail), 800.00, Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail)))
set Random_ForgottenFlail = GroupPickRandomUnit(g)
call DestroyGroup(g)
Or (less efficient)
JASS:
local location Loc = GetUnitLoc(Caster_ForgottenFlail)
local unit Random_ForgottenFlail
set bj_wantDestroyGroup = true
set Random_ForgottenFlail = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(800.00, Loc, Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail))))
call RemoveLocation(Loc)
Those are coordinates, they are more efficient and more easy to use than crappy locations.
Now, there are also nullification leaks, should be like this:
JASS:
local group g = CreateGroup()
local unit Caster_ForgottenFlail = GetTriggerUnit()
local unit Random_ForgottenFlail
call GroupEnumUnitsInRange(g, GetUnitX(Caster_ForgottenFlail), GetUnitY(Caster_ForgottenFlail), 800.00, Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail)))
set Random_ForgottenFlail = GroupPickRandomUnit(g)
call DestroyGroup(g)
set g = null
set Caster_ForgottenFlail = null
set Random_ForgottenFlail = null
If you're using location + bj_wantDestroyGroup then you should nullify the location too (you should nullify anything that's not an integer, boolean, real, string or code)
is wrong, because the function can't take parameters if given as parameters, moreover, code type can't take parameters (because the parameter is code). A workaround would be something like this (this is how your final code should look like):
JASS:
function Trig_Forgotten_Flail_Filter takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(bj_ghoul[100]))
endfunction
function Trig_Forgotten_Flail_Actions takes nothing returns nothing
local group g = CreateGroup()
local unit Caster_ForgottenFlail = GetTriggerUnit()
local unit Random_ForgottenFlail
set bj_ghoul[100] = Caster_ForgottenFlail
call GroupEnumUnitsInRange(g, GetUnitX(Caster_ForgottenFlail), GetUnitY(Caster_ForgottenFlail), 800.00, Condition(function Trig_Forgotten_Flail_Filter))
set Random_ForgottenFlail = GroupPickRandomUnit(g)
call DestroyGroup(g)
set g = null
set Caster_ForgottenFlail = null
set Random_ForgottenFlail = null
endfunction
Explanation: bj_ghoul[100] is a global unit array variable inside wc3, better to use existing variables than creating new ones, right? Note that I'm using GetFilterUnit() in Trig_Forgotten_Flail_Filter function, because I'm filtering via GroupEnum
Actually, no, bj_ghoul is like any other global variable, I just used it to transfer Caster_ForgottenFlail to Trig_Forgotten_Flail_Filter function so I can filter the group. The reason that usage of a global is MUI in this case is because the filter (Condition() function) is generated instantly (with no waits), it's like a GUI code without waits, it's impossible to interfere if it's executed in an instant. Understand?
I'm surprised GetSpellAbilityUnit isn't GetCastingUnitBJ or something, though, but meh, so be it. There are natives like that that should be ignored anyways.
They seem to have a liking for bloating the number of native event responses, for units. Just use GetTriggerUnit unless you can't (which is very rare)
I was just giving an example, your sig inspired me
I'm surprised GetSpellAbilityUnit isn't GetCastingUnitBJ or something, though, but meh, so be it. There are natives like that that should be ignored anyways.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.