Why won't my Globals Work?

theXact

New Member
Reaction score
0
So I have this code for a spell, and I need to use Global Variables in order to make it work (at least thats the only way I can think of)

Anyway, maybe I'm initializing them wrong and I don't realize it but this is how the tutorials told me to do it....

If someone could figure out why they don't work that would be great! Thanks

I am using vJASS

JASS:
globals
    unit Hero_Caster
    integer Jump_Number
endglobals

function HauntJASS_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A01G'
endfunction

function CheckGroup takes nothing returns boolean
    return IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitEnemy(GetFilterUnit() , GetOwningPlayer(GetTriggerUnit())) and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE)>0
endfunction

//function Everlasting_Horrors takes unit Target returns nothing
//    local group Everlasting_Group = CreateGroup()
//    local boolexpr Group_Check = Condition (function CheckGroup)
//    local unit DCS
//   if(Jump_Number > 0)then
//        call GroupEnumUnitsInRangeOfLoc(Everlasting_Group, GetUnitLoc(Target), 600, Group_Check )
//        set DCS = CreateUnit(GetOwningPlayer(Hero_Caster),'e001',GetUnitX(Target),GetUnitY(Target),270) // DCS = Dummy Caster Sleep
//        call UnitApplyTimedLife(DCS,'BTLF',.25)
//        call UnitAddAbility(DCS,'A01G')
//        call SetUnitAbilityLevel(DCS,'A01G',GetUnitAbilityLevel(Hero_Caster, 'A01G'))
//        set Target = GroupPickRandomUnit(Everlasting_Group)
//        call IssueTargetOrderById(DCS,OrderId("thunderbolt"),Target)
//        call SetUnitPathing(DCS,false)
//        call SetUnitInvulnerable(DCS,true)
//        set Jump_Number = Jump_Number - 1
//    endif
//    call DestroyGroup(Everlasting_Group)
//    call DestroyBoolExpr(Group_Check)
//    set DCS = null
//    set Target = null
//    endfunction

function Return_Caster takes unit Target, unit Caster, integer Count returns nothing
    local unit DCS = CreateUnit(GetOwningPlayer(Hero_Caster),'e001',GetUnitX(Target),GetUnitY(Target),270) // DCS = Dummy Caster Sleep
    call UnitApplyTimedLife(DCS,'BTLF',0.25)
    call UnitAddAbility(DCS,'A01I')
    call SetUnitAbilityLevel(DCS,'A01I',Count)
    call SetUnitScale(DCS, 1.20, 1.20, 1.20)
    call SetUnitState(Caster, UNIT_STATE_LIFE, GetUnitState(Hero_Caster, UNIT_STATE_LIFE) - 1)
    call IssueTargetOrderById(DCS,OrderId("deathcoil"),Hero_Caster)
    call SetUnitPathing(DCS,false)
    call SetUnitInvulnerable(DCS,true)
    set Count = 0
    set Caster = null
    set Target = null
    set Hero_Caster = null
endfunction

function Sleep_Damage takes unit Target, unit Caster, unit DCS returns nothing
    local integer Count = 1
    loop
        exitwhen (GetUnitAbilityLevel(Target, 'B00I') > 0) == false and (GetUnitAbilityLevel(Target, 'B00J') > 0) == false
        call TriggerSleepAction (1.)
        if (GetUnitAbilityLevel(Target, 'B00I') > 0) then
            if(GetUnitState(Target,UNIT_STATE_LIFE)>50)then
                call SetUnitState(Target,UNIT_STATE_LIFE,GetUnitState(Target,UNIT_STATE_LIFE)-50)
                set Count = Count + 1
            else
                call UnitDamageTarget(DCS,Target,100,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
                set Count = Count + 1
            endif
        endif
        exitwhen (GetUnitAbilityLevel(Target, 'B00I') > 0) == false and (GetUnitAbilityLevel(Target, 'B00J') > 0) == false
    endloop
    call Return_Caster(Target, Caster, Count)
    set Caster = null
    set Target = null
    set Hero_Caster = null
    set DCS = null
endfunction

function Cast_Sleep takes unit Target, unit Caster, integer AL returns nothing
    local unit DCS // Dummy Caster
    loop   
        if(GetUnitAbilityLevel(Target, 'B00J') > 0) then
            set DCS = CreateUnit(GetOwningPlayer(Caster),'e001',GetUnitX(Caster),GetUnitY(Caster),270) // DCS = Dummy Caster Sleep
            call UnitApplyTimedLife(DCS,'BTLF',10)
            call UnitAddAbility(DCS,'A01H')
            call SetUnitAbilityLevel(DCS,'A01H',AL)
            call IssueTargetOrderById(DCS,OrderId("sleep"),Target)
            call SetUnitPathing(DCS,false)
            call SetUnitInvulnerable(DCS,true)
        endif
        exitwhen GetUnitAbilityLevel(Target, 'B00J') > 0
        call TriggerSleepAction( 0.01 )
    endloop
    call Sleep_Damage(Target, Caster, DCS)
    if(GetUnitAbilityLevel(Caster, 'A01M')>0)then
        set Jump_Number = GetUnitAbilityLevel(Caster, 'A01M') + 1
        //call Everlasting_Horrors(Target)
    endif
    set DCS = null
    set Caster = null
    set Target = null
    set Hero_Caster = null
    set AL = 0
endfunction

function Trig_HauntJASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Target = GetSpellTargetUnit()
    local integer AL = GetUnitAbilityLevel(Caster, 'A01G') //ability level
    if( IsUnitType(Caster, UNIT_TYPE_HERO)) then
       set Hero_Caster = Caster
    endif
    call Cast_Sleep(Target, Caster, AL)
    set Caster = null
    set Target = null
    set AL = 0
endfunction

//===========================================================================
function InitTrig_HauntJASS takes nothing returns nothing
    local trigger gg_trg_HauntJASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_HauntJASS, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition ( gg_trg_HauntJASS, Condition (function HauntJASS_Conditions) )
    call TriggerAddAction( gg_trg_HauntJASS, function Trig_HauntJASS_Actions )
endfunction
 

WilliamPa

Active Member
Reaction score
51
I don't see anything wrong in the globals block.

Please note that syntax check will not allow vJass to pass through, instead, saving map shows the errors correctly(in jasspack).
 

Exide

I am amazingly focused right now!
Reaction score
448
I suggest you delcare all your globals upon initialization. (Especially the integer -one.)

Like this:

JASS:

globals
    unit Hero_Caster = null
    integer Jump_Number = 0
endglobals


(This is also a good thing to do when handling grups, forces, timers, etc.)
 

theXact

New Member
Reaction score
0
OK so now it's not working anymore, it worked twice maybe then stopped. now if I disable the trigger that declares them (and the functions that use them) it works, but if I enable that trigger (still keeping the functions that use them disables) it wont run. I'll link Code:

set to run on Map Intialization
JASS:
globals
    unit Hero_Caster = null
    integer Jump_Number = 0
endglobals

function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
    local trigger gg_trg_Untitled_Trigger_003 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_003, function Trig_Untitled_Trigger_003_Actions )
endfunction


JASS:
function HauntJASS_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A01G'
endfunction

function CheckGroup takes nothing returns boolean
    return IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitEnemy(GetFilterUnit() , GetOwningPlayer(GetTriggerUnit())) and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE)>0
endfunction

//function Everlasting_Horrors takes unit Target returns nothing
//    local group Everlasting_Group = CreateGroup()
//    local boolexpr Group_Check = Condition (function CheckGroup)
//    local unit DCS
//    if(Jump_Number > 0)then
//        call GroupEnumUnitsInRangeOfLoc(Everlasting_Group, GetUnitLoc(Target), 600, Group_Check )
//        set DCS = CreateUnit(GetOwningPlayer(Hero_Caster),'e001',GetUnitX(Target),GetUnitY(Target),270) // DCS = Dummy Caster Sleep
//        call UnitApplyTimedLife(DCS,'BTLF',.25)
//        call UnitAddAbility(DCS,'A01G')
//        call SetUnitAbilityLevel(DCS,'A01G',GetUnitAbilityLevel(Hero_Caster, 'A01G'))
//        set Target = GroupPickRandomUnit(Everlasting_Group)
//        call IssueTargetOrderById(DCS,OrderId("thunderbolt"),Target)
//        call SetUnitPathing(DCS,false)
//        call SetUnitInvulnerable(DCS,true)
//        set Jump_Number = Jump_Number - 1
//    endif
//    call DestroyGroup(Everlasting_Group)
//    call DestroyBoolExpr(Group_Check)
//    set DCS = null
//    set Target = null
  //  endfunction

//function Return_Caster takes unit Target, unit Caster, integer Count returns nothing
//    local unit DCS = CreateUnit(GetOwningPlayer(Hero_Caster),'e001',GetUnitX(Target),GetUnitY(Target),270) // DCS = Dummy Caster Sleep
//    call UnitApplyTimedLife(DCS,'BTLF',0.25)
//    call UnitAddAbility(DCS,'A01I')
//    call SetUnitAbilityLevel(DCS,'A01I',Count)
//    call SetUnitScale(DCS, 1.20, 1.20, 1.20)
//    call SetUnitState(Caster, UNIT_STATE_LIFE, GetUnitState(Hero_Caster, UNIT_STATE_LIFE) - 1)
//    call IssueTargetOrderById(DCS,OrderId("deathcoil"),Hero_Caster)
//    call SetUnitPathing(DCS,false)
//    call SetUnitInvulnerable(DCS,true)
//    set Count = 0
//    set Caster = null
//    set Target = null
//endfunction

function Sleep_Damage takes unit Target, unit Caster, unit DCS returns nothing
    local integer Count = 1
    loop
        exitwhen (GetUnitAbilityLevel(Target, 'B00I') > 0) == false and (GetUnitAbilityLevel(Target, 'B00J') > 0) == false
        call TriggerSleepAction (1.)
        if (GetUnitAbilityLevel(Target, 'B00I') > 0) then
            if(GetUnitState(Target,UNIT_STATE_LIFE)>50)then
                call SetUnitState(Target,UNIT_STATE_LIFE,GetUnitState(Target,UNIT_STATE_LIFE)-50)
                set Count = Count + 1
            else
                call UnitDamageTarget(DCS,Target,100,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
                set Count = Count + 1
            endif
        endif
        exitwhen (GetUnitAbilityLevel(Target, 'B00I') > 0) == false and (GetUnitAbilityLevel(Target, 'B00J') > 0) == false
    endloop
    //call Return_Caster(Target, Caster, Count)
    set Caster = null
    set Target = null
    set DCS = null
endfunction

function Cast_Sleep takes unit Target, unit Caster, integer AL returns nothing
    local unit DCS // Dummy Caster
    loop   
        if(GetUnitAbilityLevel(Target, 'B00J') > 0) then
            set DCS = CreateUnit(GetOwningPlayer(Caster),'e001',GetUnitX(Caster),GetUnitY(Caster),270) // DCS = Dummy Caster Sleep
            call UnitApplyTimedLife(DCS,'BTLF',10)
            call UnitAddAbility(DCS,'A01H')
            call SetUnitAbilityLevel(DCS,'A01H',AL)
            call IssueTargetOrderById(DCS,OrderId("sleep"),Target)
            call SetUnitPathing(DCS,false)
            call SetUnitInvulnerable(DCS,true)
        endif
        exitwhen GetUnitAbilityLevel(Target, 'B00J') > 0
        call TriggerSleepAction( 0.01 )
    endloop
    call Sleep_Damage(Target, Caster, DCS)
    //if(true)then //GetUnitAbilityLevel(Hero_Caster, 'A01M')>0
        //call Everlasting_Horrors(Target)
    //endif
    set DCS = null
    set Caster = null
    set Target = null
    set AL = 0
endfunction

function Trig_HauntJASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Target = GetSpellTargetUnit()
    local integer AL = GetUnitAbilityLevel(Caster, 'A01G') //ability level
    if( IsUnitType(Caster, UNIT_TYPE_HERO)) then
       //set Hero_Caster = Caster  //set Jump_Number = GetUnitAbilityLevel(Hero_Caster, 'A01M') + 1
    endif
    call Cast_Sleep(Target, Caster, AL)
    set Caster = null
    set Target = null
    set AL = 0
endfunction

//===========================================================================
function InitTrig_HauntJASS takes nothing returns nothing
    local trigger gg_trg_HauntJASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_HauntJASS, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition ( gg_trg_HauntJASS, Condition (function HauntJASS_Conditions) )
    call TriggerAddAction( gg_trg_HauntJASS, function Trig_HauntJASS_Actions )
endfunction
 

ZugZugZealot

New Member
Reaction score
33
The reason why it's suggested you define them in declaration is because Warcraft III breaks easily to the notion of trying to work with null values. Sadly it's not smart enough to determine that in...
JASS:
set i = i + 1
whereas i = null it would be i = null + 1, it will just stop there and everything after will never happen; smarter languages will just treat null as 0 by default. You don't necessarily need to define them right away, just make sure you give them a value before handling them.

Anyways, I'd like to know why you even want to use a global for Hero_Caster in those functions, when Caster = Hero_Caster. Have you tried adding the argument "takes unit Caster" to Everlasting_Horrors and just replacing all of your Hero_Caster placements with Caster? >_>
 

theXact

New Member
Reaction score
0
Basically what the spell is doing, is, if you take out everything to do with everlasting_horrors, it send out a projectile, when it hits the target it puts it to sleep, the unit takes damage per second, then after a length of time determined by ability level it will wake up and another projectile will emerge which will go back to the original caster and heal him for the damage done during that time period. What everlasting horrors does if its not aperant, is cause it to bounce to different targets an amount of times = to another passive spell. The reason for Hero_Caster needing to be global is because it will call the trigger again when the bounce occurs causing a new Caster to form (dummy caster), and I want the healing from that one to go back to the original caster, not the dummy caster. Same applies for why everlasting count needs to be global, so it can count the number of bounces.

I'm currently looking into methods of doing this using a loop as aposed to recallig the trigger.
 

theXact

New Member
Reaction score
0
K so I figured out a way to do it without globals, in my mind it should work. Only problems is 2 of the functions call eachother and I dont know how to do that as I cannot put both functions in front of eachother. Sorry for my newbyness :)

JASS:
function HauntJASS_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A01G'
endfunction

function CheckGroup takes nothing returns boolean
    return IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitEnemy(GetFilterUnit() , GetOwningPlayer(GetTriggerUnit())) and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE)>0
endfunction

function Return_Caster takes unit Target, unit Caster, integer Count, unit Hero_Caster returns nothing
    local unit DCS = CreateUnit(GetOwningPlayer(Hero_Caster),'e001',GetUnitX(Target),GetUnitY(Target),270) // DCS = Dummy Caster Sleep
    call UnitApplyTimedLife(DCS,'BTLF',0.25)
    call UnitAddAbility(DCS,'A01I')
    call SetUnitAbilityLevel(DCS,'A01I',Count)
    call SetUnitScale(DCS, 1.20, 1.20, 1.20)
    call SetUnitState(Hero_Caster, UNIT_STATE_LIFE, GetUnitState(Hero_Caster, UNIT_STATE_LIFE) - 1)
    call IssueTargetOrderById(DCS,OrderId("deathcoil"),Hero_Caster)
    call SetUnitPathing(DCS,false)
    call SetUnitInvulnerable(DCS,true)
    set Count = 0
    set Caster = null
    set Target = null
    set Hero_Caster = null
endfunction

function Sleep_Damage takes unit Target, unit Caster, unit DCS, unit Hero_Caster returns nothing
    local integer Count = 1
    loop
        exitwhen (GetUnitAbilityLevel(Target, 'B00I') > 0) == false and (GetUnitAbilityLevel(Target, 'B00J') > 0) == false
        call TriggerSleepAction (1.)
        if (GetUnitAbilityLevel(Target, 'B00I') > 0) then
            if(GetUnitState(Target,UNIT_STATE_LIFE)>50)then
                call SetUnitState(Target,UNIT_STATE_LIFE,GetUnitState(Target,UNIT_STATE_LIFE)-50)
                set Count = Count + 1
            else
                call UnitDamageTarget(DCS,Target,100,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
                set Count = Count + 1
            endif
        endif
        exitwhen (GetUnitAbilityLevel(Target, 'B00I') > 0) == false and (GetUnitAbilityLevel(Target, 'B00J') > 0) == false
    endloop
    call Return_Caster(Target, Caster, Count, Hero_Caster)
    set Caster = null
    set Target = null
    set DCS = null
    set Hero_Caster = null
endfunction

function Cast_Sleep takes unit Target, unit Caster, unit Hero_Caster, integer Jump_Number returns nothing
    local unit DCS // Dummy Caster
    local integer AL = GetUnitAbilityLevel(Caster, 'A01G') //ability level
    loop   
        if(GetUnitAbilityLevel(Target, 'B00J') > 0) then
            set DCS = CreateUnit(GetOwningPlayer(Caster),'e001',GetUnitX(Caster),GetUnitY(Caster),270) // DCS = Dummy Caster Sleep
            call UnitApplyTimedLife(DCS,'BTLF',10)
            call UnitAddAbility(DCS,'A01H')
            call SetUnitAbilityLevel(DCS,'A01H',AL)
            call IssueTargetOrderById(DCS,OrderId("sleep"),Target)
            call SetUnitPathing(DCS,false)
            call SetUnitInvulnerable(DCS,true)
        endif
        exitwhen GetUnitAbilityLevel(Target, 'B00J') > 0
        call TriggerSleepAction( 0.01 )
    endloop
    call Sleep_Damage(Target, Caster, DCS, Hero_Caster)
    if(GetUnitAbilityLevel(Hero_Caster, 'A01M')>0)then 
        call Everlasting_Horrors(Target, Hero_Caster, Jump_Number)
    endif
    set DCS = null
    set Caster = null
    set Target = null
    set AL = 0
    set Hero_Caster = null
    set Jump_Number = 0
endfunction

function Everlasting_Horrors takes unit Target, unit Hero_Caster, integer Jump_Number returns nothing
    local group Everlasting_Group = CreateGroup()
    local boolexpr Group_Check = Condition (function CheckGroup)
    local unit DCS
    if(Jump_Number > 0)then
        call GroupEnumUnitsInRangeOfLoc(Everlasting_Group, GetUnitLoc(Target), 600, Group_Check )
        set DCS = CreateUnit(GetOwningPlayer(Hero_Caster),'e001',GetUnitX(Target),GetUnitY(Target),270) // DCS = Dummy Caster Sleep
        call UnitApplyTimedLife(DCS,'BTLF',.25)
        call UnitAddAbility(DCS,'A01O')
        call SetUnitAbilityLevel(DCS,'A01O',GetUnitAbilityLevel(Hero_Caster, 'A01G'))
        set Target = GroupPickRandomUnit(Everlasting_Group)
        call IssueTargetOrderById(DCS,OrderId("thunderbolt"),Target)
        call SetUnitPathing(DCS,false)
        call SetUnitInvulnerable(DCS,true)
        set Jump_Number = Jump_Number - 1
        call Cast_Sleep(Target, DCS, Hero_Caster, Jump_Number)
    endif
    call DestroyGroup(Everlasting_Group)
    call DestroyBoolExpr(Group_Check)
    set DCS = null
    set Target = null
    set Hero_Caster = null
    set Jump_Number = 0
endfunction

function Trig_HauntJASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Target = GetSpellTargetUnit()
    local unit Hero_Caster
    local integer Jump_Number
    if( IsUnitType(Caster, UNIT_TYPE_HERO)) then
       set Hero_Caster = Caster 
       set Jump_Number = GetUnitAbilityLevel(Hero_Caster, 'A01M') + 1
    endif
    call Cast_Sleep(Target, Caster, Hero_Caster, Jump_Number)
    set Caster = null
    set Target = null
    set Hero_Caster = null
endfunction

//===========================================================================
function InitTrig_HauntJASS takes nothing returns nothing
    local trigger gg_trg_HauntJASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_HauntJASS, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition ( gg_trg_HauntJASS, Condition (function HauntJASS_Conditions) )
    call TriggerAddAction( gg_trg_HauntJASS, function Trig_HauntJASS_Actions )
endfunction


Notice how Everlasting_Horrors calls Cast_Sleep under certain conditions and vice versa

I don't know how to fix that, I was thinking a Library might do it? but I'm not sure.

Tanks Everyone!
 
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