My first JASS Trigger...Causing me problems

Charapanga

New Member
Reaction score
46
Hi, well i made my first trigger, it is supposed to display a text to all players when a hero dies and reduce owning player's gold by 250 But...It doesn't even go off...and there might be Leaks cuz it kinnda lags when a hero dies...

JASS:
globals
    unit u = GetTriggerUnit() // Dying unit
    location ul = GetUnitLoc(u) // position of dying unit
    player uo = GetOwningPlayer(u) // Owner of Dying unit
    force ap = GetPlayersAll() // all players
    string pn = GetPlayerName(uo) // Player name
    integer gold = -250 // Gold lost
    texttag ft = CreateTextTagLocBJ("Died", ul, 0, 10, 0, 100, 100, 0) // Floating Text
endglobals

function PlayerDeath_Conditions takes nothing returns boolean
    return ( IsUnitType(GetTriggerUnit( ), UNIT_TYPE_HERO) == true ) // if dying unit is a hero
endfunction

function PlayerDeath_Actions takes nothing returns nothing
    call DisplayTextToForce(ap, pn+" has died, he will lose "+I2S(gold)+" gold!") // Displays the text to all players
    call AdjustPlayerStateBJ( gold, uo, PLAYER_STATE_RESOURCE_GOLD ) // Reduces the gold...
    call SetTextTagLifespanBJ( ft, 5 )
    call SetTextTagVelocityBJ( ft, 64, 90 )
    call SetTextTagFadepointBJ( ft, 3 )
    call ShowTextTagForceBJ( true, ft, ap )
endfunction

//===========================================================================
function InitTrig_PlayerDeath takes nothing returns nothing
    local trigger gg_trg_PlayerDeath = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_PlayerDeath, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition(gg_trg_PlayerDeath, Condition(function PlayerDeath_Conditions))
    call TriggerAddAction( gg_trg_PlayerDeath, function PlayerDeath_Actions )
endfunction
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Your globals are initialized when the map loads.
Most won't have any kind of meaningful content.

Those that still make sense:
- ap (then again, that's already a global, why not use it?)
- gold

All others need to be set when the action function is called...
 

Charapanga

New Member
Reaction score
46
Oh, okay...well i added them into locals, and set them at the beggining of actions and it works :)

so now i know locals > globals :D
 

Viikuna

No Marlo no game.
Reaction score
265
Sometimes yea..

But since you can only use them in their own function, their usefullness is limited.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top