• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

why does this "call function" not work?

Status
Not open for further replies.
Level 3
Joined
Dec 17, 2017
Messages
39
Hey guys,
i try to call a function, but it just doesnt get called.. i cant find the reason:/
please help me

the rows of stars (*****) mark the two important parts:
JASS:
function startAbility takes unit caster, unit target, integer ab, real x, real y, real angle returns nothing
    local timer t=CreateTimer()
    // ************now this is the important part*************
    call DisplayTextToForce( GetPlayersAll(), "startAbility fuction: the call was successful." )
    //this message never appears...
    // *************************************************
    call TimerStart(t, 0.05, false, function participateAbility)
    call SaveUnitHandle(udg_TheHashtable1, GetHandleId(t), 1, caster)
    call SaveUnitHandle(udg_TheHashtable1, GetHandleId(t), 2, target)
    call SaveInteger(udg_TheHashtable1, GetHandleId(t), 3, ab)
    call SaveReal( udg_TheHashtable1, GetHandleId(t), 4, x )
    call SaveReal( udg_TheHashtable1, GetHandleId(t), 5, y )
    call SaveReal( udg_TheHashtable1, GetHandleId(t), 6, angle )
    call SaveInteger( udg_TheHashtable1, GetHandleId(t), 7, LoadInteger(udg_TheHashtable1, ab, 1)) //cyclen des timers
    set t=null
endfunction


// Melee-Attack:
function Trig_AttackMeleeNewer_Actions takes nothing returns nothing
    local unit caster
    local unit target
    local integer key
    local integer i1
    set caster=GetAttacker()
    set key = GetHandleId(caster)
    set i1 = LoadInteger(udg_TheHashtable1, key, udg_hashUnitRanged1)
    if ( i1 > 0 ) then
    else
        // ************now this is the important part*************
        // startAbility takes unit caster, unit target, integer ability, real x, real y, real angle
        call DisplayTextToForce( GetPlayersAll(), "startAbility fuction is called (from AttackMeleeNewer-Trigger." )
        //this message appears on each attack!
        call startAbility(caster, target, 'A000', GetUnitX(caster), GetUnitY(caster), GetUnitFacing(caster) )
        // *************************************************
    endif
    set caster=null
    set target=null
endfunction
//===========================================================================
function InitTrig_AttackMeleeNewer takes nothing returns nothing
    set gg_trg_AttackMeleeNewer = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_AttackMeleeNewer, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_AttackMeleeNewer, function Trig_AttackMeleeNewer_Actions )
endfunction
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
Probably the if block is evaluating to true so nothing runs (everything is under “else”). Also as I recall JASS hates empty then blocks with filled else blocks, so you should negate your if and move actions to the then instead.

Everything else in the functions is actually running (i.e. it’s not threadcrashing)? Sounds like you accidentally destroyed the force returned by GetPlayersAll() somewhere. That particular force does not need to be cleaned up so you never need to call DestroyForce on it.

You can use the simple function BJDebugMsg(“message”) for debugging text purposes.
 
Level 3
Joined
Dec 17, 2017
Messages
39
hey, thanks for your reply!
You can use the simple function BJDebugMsg(“message”) for debugging text purposes.
ah nice, I searched for that command earlier, but didnt find it ^^'

Probably the if block is evaluating to true so nothing runs (everything is under “else”). Also as I recall JASS hates empty then blocks with filled else blocks, so you should negate your if and move actions to the then instead.

Everything else in the functions is actually running (i.e. it’s not threadcrashing)? Sounds like you accidentally destroyed the force returned by GetPlayersAll() somewhere. That particular force does not need to be cleaned up so you never need to call DestroyForce on it.

Yeah but I see the message that is under the else block ("startAbility fuction is called (from AttackMeleeNewer-Trigger.") everytime the unit attacks - so the if then evaluates as false, and also the GetPlayersAll() must still exist (repeated attacks), else I couldnt see the message.
its really strange...
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
Found it: you are threadcrashing... kinda. local unit target is never assigned a value before being passed to startAbility(). It probably should be set to GetTriggerUnit() based on how I understand your trigger to work.

Side note: the "unit is attacked" event is terrible and shouldn't be used because it can be exploitively 'activated' repeatedly by spamming attack, stop, attack, stop and it will fire the event without an attack actually being launched. Instead you should use a Damage Detection System like Damage Engine 5.4.0.1 that can determine when damage is dealt by an attack.
 
Level 3
Joined
Dec 17, 2017
Messages
39
Wow, thanks man, I overlooked it, but now it works!
youre awesome:)

Side note: the "unit is attacked" event is terrible and shouldn't be used because it can be exploitively 'activated' repeatedly by spamming attack, stop, attack

I know, but in this case its alright;)

cant give you reps yet (only once every 24 hrs) but ill remember until tomorrow!
 
Status
Not open for further replies.
Top