Why does this code only display zeroes?

Reflexar

New Member
Reaction score
12
Why does this code only display zeroes when a unit is attacked?

JASS:
scope ShowDamage initializer init

globals
    real damage
endglobals

private function Actions takes nothing returns nothing
    call CreateTextTagUnitBJ( "|cffFF0000" + I2S(R2I(damage)), GetTriggerUnit(), 0, 7.3, 100, 100, 100, 0 )
    call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 120, 90 )
    call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
    call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 1.00 )  
endfunction

//===========================================================================
private function init takes nothing returns nothing
    set gg_trg_Show_Spell = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Show_Spell, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_Show_Spell, function Actions )
    set damage = GetEventDamage()
endfunction

endscope


Is it good to just use scopes to be able to have private functions?
 

Romek

Super Moderator
Reaction score
963
> set damage = GetEventDamage()
There is no GetEventDamage in that init function. Nothing triggers it.
Move that line to the 'Actions' function.
Although it wouldn't help there either, as EVENT_PLAYER_UNIT_ATTACKED doesn't register damage.

Use a damage detection engine.

> Is it good to just use scopes to be able to have private functions?
That's probably the only reason to use them, along with initializers.
Also, private variables help too.
 

Romek

Super Moderator
Reaction score
963
It's a unit event, not a player unit event; EVENT_UNIT_DAMAGED.
You need to create the event for every unit on the map, and add it for every unit that gets created.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top