[JASS] Compiling error

Status
Not open for further replies.
Level 5
Joined
Aug 3, 2005
Messages
150
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 =(
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
First, a little improvements:

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)

The error in your code is that:

Condition(function Trig_Forgotten_Flail_Filter(Caster_ForgottenFlail))

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
 
Level 5
Joined
Aug 3, 2005
Messages
150
i suppose i should have told you i'm setting the Random_ForgottenFlail inside a loop every few seconds

didn't think it was necessary because I thought I was looking for a syntax error

can i still use bj_ghoul in a non-instant spell and still have multi-instanceability?
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
i suppose i should have told you i'm setting the Random_ForgottenFlail inside a loop every few seconds

didn't think it was necessary because I thought I was looking for a syntax error

Oh :)

can i still use bj_ghoul in a non-instant spell and still have multi-instanceability?

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?

Did you understand why the error occured?
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Goddamnit HT, is said they do the same thing, I wasn't talking about performance.

For example, DoNothing() does the same thing as this:

JASS:
function DoNothingBlabla takes nothing returns nothing
    if 1 == 2 then
        call DoNothing()
    else
        call DoNothing()
    endif
endfunction


Those to functions do the same, but the performance is not the same. Understand? :p
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
You don't need to call DoNothing to Do nothing ;P

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)
 
Status
Not open for further replies.
Top