• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Function won't allow any parameters ??

Status
Not open for further replies.
Level 8
Joined
Feb 3, 2013
Messages
277
JASS:
private function CE_Damage takes unit a returns nothing
        if IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(a)) then
            call UnitDamageTarget(a, GetEnumUnit(), DAMAGE, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
        endif
endfunction
    
call ForGroup(g, function CE_Damage(u))

I have something like this in my trigger,.. but why does it give me a compile error on the ForGroup line saying "Syntax Error Unexpected: "(""?? Am i Not allowed to have parameters for a ForGroup function?
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
JASS:
private function CE_Damage takes nothing returns nothing
    if IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(a)) then
        call UnitDamageTarget(a, GetEnumUnit(), DAMAGE, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
    endif
endfunction

private function enumUnits takes nothing returns nothing    
    call ForGroup(g, function CE_Damage)
endfunction
 
Level 8
Joined
Feb 3, 2013
Messages
277
^Is a global variable?

it currently is.. but I'm trying to find a way to pass the unit onto this function, so I can make this spell MUI.. I actually have a MUI version, but lets just say I don't like the way it currently works - it creates a group every 0.02 seconds.... and is prone to lag and leaks...

I'm trying to make a spell that on cast, creates mini explosions and deals damage to units within an aoe.

The issue is the for group call.. I'm trying to make it detect if a unit in a group is an enemy of the triggering unit, but I don't know how to pass the triggering unit to the CE_Damage function without using a global variable :/
JASS:
scope CExplosion initializer init 

    globals
        private constant hashtable hash = InitHashtable()
        private constant integer AB_ID = 'A000'                             // RAW ID of the Ability
        private constant string FX = "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl"   // FX of the explosion
        private constant boolean ALLOW_STRUCTURE = TRUE                     // Are structures allowed
        private constant boolean ALLOW_FLYING = TRUE                        // Are flying units allowed
        private constant real DAMAGE = 5                                   // Damage dealt
        private constant real AOE = 150                                     // AoE of each explosion
        private unit a = GetTriggerUnit()
    endglobals
    
    private function CE_Cond takes nothing returns boolean
        return GetSpellAbilityId() == AB_ID
    endfunction
    
    private function CE_Filter takes nothing returns boolean
        return TRUE
    endfunction
    
    private function CE_Damage takes nothing returns nothing
        if IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(a)) then
            call UnitDamageTarget(a, GetEnumUnit(), DAMAGE, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
        endif
    endfunction
    
    private function CE_Boom takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer i = LoadInteger(hash, GetHandleId(t), 1)
        local unit u = LoadUnitHandle(hash, GetHandleId(t), 2)
        local real ang = GetRandomReal(0, 360)
        local real o = GetRandomReal(0, 380)
        local real x = LoadReal(hash, GetHandleId(t), 3) + o * Cos(ang * bj_DEGTORAD)
        local real y = LoadReal(hash, GetHandleId(t), 4) + o * Sin(ang * bj_DEGTORAD)
        local unit fog = null
        
        if i < 200 then
            call DestroyEffect(AddSpecialEffect(FX, x, y))
            call SaveInteger(hash, GetHandleId(t), 1, i + 1)
            call ForGroup(LoadGroupHandle(hash, GetHandleId(t), 5), function CE_Damage)
            call GroupEnumUnitsInRange(LoadGroupHandle(hash, GetHandleId(t), 5), LoadReal(hash, GetHandleId(t), 3), LoadReal(hash, GetHandleId(t), 4), 420, Filter(function CE_Filter))
        elseif i == 200 then
            call PauseTimer(t)
            call DestroyGroup(LoadGroupHandle(hash, GetHandleId(t), 5))
            call FlushChildHashtable(hash, GetHandleId(t))
            call DestroyTimer(t)
        endif
        
        set t = null
        set u = null
    endfunction
    
    private function CE_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local group g = CreateGroup()
        local real x = GetSpellTargetX()
        local real y = GetSpellTargetY()
        local integer i = 0
        local timer t = CreateTimer()
        
        set a = GetTriggerUnit()
        
        call GroupEnumUnitsInRange(g, x, y, 420, Filter(function CE_Filter))
        call SaveGroupHandle(hash, GetHandleId(t), 5, g)
        call SaveInteger(hash, GetHandleId(t), 1, i)
        call SaveReal(hash, GetHandleId(t), 3, x)
        call SaveReal(hash, GetHandleId(t), 4, y)
        call SaveUnitHandle(hash, GetHandleId(t), 2, u)
        call TimerStart(t, 0.02, true, function CE_Boom)

        set t = null
        set u = null
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function CE_Cond))
        call TriggerAddAction(t, function CE_Actions)
        set t = null
    endfunction

endscope

Once again thanks to everyone who posted
And especially to Zeatherann who answered my question
 
Last edited:
u have to use a global variable to pass it to a ForGroup call.

note: u do not need the local unit u = gettriggerunit in this one just change the values to a instead of u

JASS:
    private function CE_Actions takes nothing returns nothing
        local group g = CreateGroup()
        local real x = GetSpellTargetX()
        local real y = GetSpellTargetY()
        local integer i = 0
        local timer t = CreateTimer()
        set a = GetTriggerUnit()
        call GroupEnumUnitsInRange(g, x, y, 420, null)
        call SaveGroupHandle(hash, GetHandleId(t), 5, g)
        call SaveInteger(hash, GetHandleId(t), 1, i)
        call SaveReal(hash, GetHandleId(t), 3, x)
        call SaveReal(hash, GetHandleId(t), 4, y)
        call SaveUnitHandle(hash, GetHandleId(t), 2, a)
        call TimerStart(t, 0.02, true, function CE_Boom)
        set t = null
    endfunction

this is always returning true

JASS:
call GroupEnumUnitsInRange(LoadGroupHandle(hash, GetHandleId(t), 5), LoadReal(hash, GetHandleId(t), 3), LoadReal(hash, GetHandleId(t), 4), 420, Filter(function CE_Filter))

you could change it to this and get rid of the function CE_Filter

JASS:
call GroupEnumUnitsInRange(LoadGroupHandle(hash, GetHandleId(t), 5), LoadReal(hash, GetHandleId(t), 3), LoadReal(hash, GetHandleId(t), 4), 420, null)
 
Level 8
Joined
Feb 3, 2013
Messages
277
using a null as the filter, leaks for groupenumunits - is wat I read.

JASS:
    private function CE_Damage takes group ga, unit a returns nothing
        local unit fog = null
        loop
            set fog = FirstOfGroup(ga)
            exitwhen fog == null
                if IsUnitEnemy(fog, GetOwningPlayer(a)) then
                    call UnitDamageTarget(a, fog, DAMAGE, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
                endif
            call GroupRemoveUnit(ga, fog)
        endloop
    endfunction
this shoud make things MUI, still thanks for ur post
 
Status
Not open for further replies.
Top