Globals And Certain Triggers Breaking Map

WolfieeifloW

WEHZ Helper
Reaction score
372
I have six triggers that use [ljass]globals[/ljass], and quite a few of the same ones.
I'm trying to make a trigger with a globals block so they can all call from the same one.
Now, when I try to use this global [ljass]globals[/ljass] block, 3/6 of my triggers make the map not load, and instead just go to the main screen when I try to test map.

I'm going to show all my triggers so people can see, and hopefully help.


Globals (Contains all the globals; When I try to use globals from here, the first three triggers make the map not work):
JASS:
globals
    //Presence IDs
    constant integer f = 'A000'
    constant integer u = 'A001'
    constant integer fd = 'A003'
    constant integer ud = 'A002'
        
    //Frost IDs
    constant integer Ob = 'A006'
    constant integer IT = 'A008'
    constant integer CI = 'A005'
        
    //Unholy IDs
    constant integer PS = 'A009'
    constant integer DC = 'A007'
    constant integer UF = 'A00A'
    
    constant integer SB = 'A004'
endglobals

FULearn (Breaks when trying to use [ljass]globals[/ljass] from 'Globals':
JASS:
scope FULearn initializer FULearnInit
    
    //globals
        //private constant integer SB = 'A004'
        //private constant integer f = 'A000'
        //private constant integer u = 'A001'
        //private constant integer fd = 'A003'
    //endglobals

    private function FUL takes unit t returns nothing
        call UnitAddAbility(t, SB)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), u, false)
        call SetUnitAbilityLevel(t, f, 1)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), SB, false)
    endfunction

    private function Conditions takes nothing returns boolean
        if GetLearnedSkill() == fd then
            call FUL(GetLearningUnit())
        endif
        return false
    endfunction

    private function FULearnInit takes nothing returns nothing
        local integer index = 0
        local trigger tr = CreateTrigger()
        loop
            call TriggerRegisterPlayerUnitEvent(tr, Player(index), EVENT_PLAYER_HERO_SKILL, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(tr, Condition(function Conditions))
    endfunction
    
endscope

DKLevel (Breaks when trying to use [ljass]globals[/ljass] from 'Globals':
JASS:
scope DKLevel initializer DKLevelInit

    //globals
        //private constant integer f = 'A000'
        //private constant integer u = 'A001'
        //private constant integer fd = 'A003'
        //private constant integer ud = 'A002'
        //private constant integer Ob = 'A006'
        //private constant integer IT = 'A008'
        //private constant integer CI = 'A005'
        //private constant integer PS = 'A009'
        //private constant integer DC = 'A007'
        //private constant integer UF = 'A00A'
    //endglobals

    private function DKL takes unit t returns nothing
        local integer l = GetUnitAbilityLevel(t, u)
        
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), u, false)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), f, true)
        call UnitRemoveAbility(t, ud)
        call UnitAddAbility(t, fd)
        call SetUnitAbilityLevel(t, fd, l)
        call SetUnitAbilityLevel(t, f, l)
        
        //Ability 1
        if (GetUnitAbilityLevel(t, PS) >=1) then
            set l = GetUnitAbilityLevel(t, PS)
            call SetPlayerAbilityAvailable(GetOwningPlayer(t), PS, false)
            call SetPlayerAbilityAvailable(GetOwningPlayer(t), Ob, true)
            call SetUnitAbilityLevel(t, Ob, l)
        endif
        //Ability 2
        if (GetUnitAbilityLevel(t, DC) >=1) then
            set l = GetUnitAbilityLevel(t, DC)
            call SetPlayerAbilityAvailable(GetOwningPlayer(t), DC, false)
            call SetPlayerAbilityAvailable(GetOwningPlayer(t), IT, true)
            call SetUnitAbilityLevel(t, IT, l)
        endif
        //Ability 3
        if (GetUnitAbilityLevel(t, UF) >= 1) then
            set l = GetUnitAbilityLevel(t, UF)
            call SetPlayerAbilityAvailable(GetOwningPlayer(t), UF, false)
            call SetPlayerAbilityAvailable(GetOwningPlayer(t), CI, true)
            call SetUnitAbilityLevel(t, CI, l)
        endif
    endfunction

    private function Conditions takes nothing returns boolean
        if GetUnitTypeId(GetLevelingUnit()) == 'U000' and GetUnitAbilityLevel(GetLevelingUnit(), u) >= 1 then
            call DKL(GetLevelingUnit())
        endif
        return false
    endfunction

    private function DKLevelInit takes nothing returns nothing
        local integer index = 0
        local trigger tr = CreateTrigger()
        loop
            call TriggerRegisterPlayerUnitEvent(tr, Player(index), EVENT_PLAYER_HERO_LEVEL, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(tr, Condition(function Conditions))
    endfunction

endscope

FUPresence (Breaks when trying to use [ljass]globals[/ljass] from 'Globals':
JASS:
scope FUPresence initializer FUPresenceInit

    //globals
        ////Presence IDs
        //private constant integer f = 'A000'
        //private constant integer u = 'A001'
        //private constant integer fd = 'A003'
        //private constant integer ud = 'A002'
        
        ////Frost IDs
        //private constant integer Ob = 'A006'
        //private constant integer IT = 'A008'
        //private constant integer CI = 'A005'
        ////private constant integer MF =  ''
        
        ////Unholy IDs
        //private constant integer PS = 'A009'
        //private constant integer DC = 'A007'
        //private constant integer UF = 'A00A'
        ////private constant integer DG = ''
    //endglobals
    
    private function FU takes unit t, integer a, integer b, integer ab, integer bb returns nothing
        local integer l
        
        //Switch the presences
        set l = GetUnitAbilityLevel(t, ab)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), a, false)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), b, true)
        call UnitRemoveAbility(t, ab)
        call UnitAddAbility(t, bb)
        call SetUnitAbilityLevel(t, bb, l)
        call SetUnitAbilityLevel(t, b, l)
        
        if (ab == fd) then //F2U
            //Ability 1
            if (GetUnitAbilityLevel(t, Ob) >= 1) then
                set l = GetUnitAbilityLevel(t, Ob)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), Ob, false)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), PS, true)
                call SetUnitAbilityLevel(t, PS, l)
            endif
            //Ability 2
            if (GetUnitAbilityLevel(t, IT) >=1) then
                set l = GetUnitAbilityLevel(t, IT)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), IT, false)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), DC, true)
                call SetUnitAbilityLevel(t, DC, l)
            endif
            //Ability 3
            if (GetUnitAbilityLevel(t, CI) >= 1) then
                set l = GetUnitAbilityLevel(t, CI)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), CI, false)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), UF, true)
                call SetUnitAbilityLevel(t, UF, l)
            endif
            //Ability 4
            //if (GetUnitAbilityLevel(t, ) >=1) then
            //endif
        elseif (ab == ud) then //U2F
            //Ability 1
            if (GetUnitAbilityLevel(t, PS) >=1) then
                set l = GetUnitAbilityLevel(t, PS)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), PS, false)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), Ob, true)
                call SetUnitAbilityLevel(t, Ob, l)
            endif
            //Ability 2
            if (GetUnitAbilityLevel(t, DC) >=1) then
                set l = GetUnitAbilityLevel(t, DC)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), DC, false)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), IT, true)
                call SetUnitAbilityLevel(t, IT, l)
            endif
            //Ability 3
            if (GetUnitAbilityLevel(t, UF) >= 1) then
                set l = GetUnitAbilityLevel(t, UF)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), UF, false)
                call SetPlayerAbilityAvailable(GetOwningPlayer(t), CI, true)
                call SetUnitAbilityLevel(t, CI, l)
            endif
            //Ability 4
            //if (GetUnitAbilityLevel(t, ) >=1) then
            //endif
        endif
    endfunction
    
    private function Conditions takes nothing returns boolean
        if GetSpellAbilityId() == fd then
            call FU(GetTriggerUnit(), f, u, fd, ud)
        elseif GetSpellAbilityId() == ud then
            call FU(GetTriggerUnit(), u, f, ud, fd)
        endif
        return false
    endfunction
    
    private function FUPresenceInit takes nothing returns nothing
        local integer index = 0
        local trigger tr = CreateTrigger()
        loop
            call TriggerRegisterPlayerUnitEvent(tr, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(tr, Condition(function Conditions))
    endfunction

endscope

DKS1 (Works when trying to use [ljass]globals[/ljass] from 'Globals':
JASS:
scope DKS1 initializer DKS1Init
    
    //globals
        //private constant integer Ob = 'A006'
        //private constant integer PS = 'A009'
    //endglobals
    
    private function S1 takes unit t returns nothing
        call UnitAddAbility(t, PS)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), PS, false)
    endfunction
    
    private function Conditions takes nothing returns boolean
        if GetLearnedSkill() == Ob then
            call S1(GetLearningUnit())
        endif
        return false
    endfunction
    
    private function DKS1Init takes nothing returns nothing
        local integer index = 0
        local trigger tr = CreateTrigger()
        loop
            call TriggerRegisterPlayerUnitEvent(tr, Player(index), EVENT_PLAYER_HERO_SKILL, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(tr, Condition(function Conditions))
    endfunction

endscope

DKS2 (Works when trying to use [ljass]globals[/ljass] from 'Globals':
JASS:
scope DKS2 initializer DKS2Init
    
    //globals
        //private constant integer DC = 'A007'
        //private constant integer IT = 'A008'
    //endglobals
    
    private function S2 takes unit t returns nothing
        call UnitAddAbility(t, DC)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), DC, false)
    endfunction
    
    private function Conditions takes nothing returns boolean
        if GetLearnedSkill() == IT then
            call S2(GetLearningUnit())
        endif
        return false
    endfunction
    
    private function DKS2Init takes nothing returns nothing
        local integer index = 0
        local trigger tr = CreateTrigger()
        loop
            call TriggerRegisterPlayerUnitEvent(tr, Player(index), EVENT_PLAYER_HERO_SKILL, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(tr, Condition(function Conditions))
    endfunction

endscope

DKS3 (Works when trying to use [ljass]globals[/ljass] from 'Globals':
JASS:
scope DKS3 initializer DKS3Init
    
    //globals
        //constant integer UF = 'A00A'
        //constant integer CI = 'A005'
    //endglobals
    
    private function S3 takes unit t returns nothing
        call UnitAddAbility(t, UF)
        call SetPlayerAbilityAvailable(GetOwningPlayer(t), UF, false)
    endfunction
    
    private function Conditions takes nothing returns boolean
        if GetLearnedSkill() == CI then
            call S3(GetLearningUnit())
        endif
        return false
    endfunction
    
    private function DKS3Init takes nothing returns nothing
        local integer index = 0
        local trigger tr = CreateTrigger()
        loop
            call TriggerRegisterPlayerUnitEvent(tr, Player(index), EVENT_PLAYER_HERO_SKILL, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(tr, Condition(function Conditions))
    endfunction

endscope


I tested this by turning off all of the triggers at once; The map loads fine.
Globals, and DKS3 on; Loads.
Globals, DKS3, and DKS2; Loads.
Globals, DKS3, DKS2, and DKS1; Loads.
Globals, DKS3, DKS2, DKS1, and any of the other three; Fails.
Globals, and FULearn or DKLevel or FUPresence; Fails.

Why are those three making the map 'crash'..?


If any more information is needed or something, please let me know..
I don't want each trigger to have to have it's own globals block.
 

Romek

Super Moderator
Reaction score
963
That code tag makes the post horrible to read. I'd rather a long post to that. :p

Are you saving the map before testing it?
Does it work if the 'broken' scripts (alone, and together) and the globals are enabled, and everything else disabled?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Yepp, it's just subconscious to always hit CTRL+S before testing :p
I took out the code tags too.

With all three scripts together, it doesn't work.
Just 'FULearn' doesn't work.
Just 'DKLevel' doesn't work.
And whoa, what the heck..
Apparently with just 'FUPresence' enabled, the game actually critically errors before even showing the loading screen.

Maybe that last clue will help :p ?
 

Romek

Super Moderator
Reaction score
963
> Are you sure that the globals is going before the others?
Yes

Do the triggers work if you're using the globals from within the scopes?
If so, do you have any triggers/structs that have the same names as those globals?

The triggers themselves look fine to me. I'm positive there's another problem elsewhere. With global names such as 'u' or 'f', it's quite likely that they're being referenced somewhere where there's a local of the same name in scope, causing problems of some sort.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
If I disable the script 'Globals', and un-comment all the globals within each script, everything works fine.
These are the only six scripts in my map so far.
And there's no overlapping names.
All those global names are unique (Although I'm going to change them later, to be more specific).
 

Romek

Super Moderator
Reaction score
963
Could you upload your map or the 'inputwar3map.j' file found in the /logs folder?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I don't want my map left up for long, so if you could just let me know via PM or something when you've got it downloaded, so I can detach it please.


EDIT: Thank you.
 

Romek

Super Moderator
Reaction score
963
I'm unable to replicate your problem. I commented the globals in the scripts, enabled the globals trigger, and took it in turns enabling/disabling different combinations of the triggers.
Everything saved and loaded perfectly.

Have you updated WC3 recently (ever)?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Warcraft 3 is whatever the newest version is.
I go on b.net often.

I just enabled Globals, and commented all the other globals out.
Still going to the main screen.

Let me upload the map, as is right now, in it's not working state.

Again, please let me know when you have it.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Warcraft 3 is whatever the newest version is.
I go on b.net often.

I just enabled Globals, and commented all the other globals out.
Still going to the main screen.

Let me upload the map, as is right now, in it's not working state.

Again, please let me know when you have it.

You do have the newest JASSHelper, right? I downloaded it, and it works fine for me.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Yes, I do.
The only thing that's different, besides newest NewGen, WC3, and JassHelper, is Romek's wehack.lua.
 

Romek

Super Moderator
Reaction score
963
Do any other maps with public constant globals work?
Could you upload your 'outputwar3map.j'?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
One of my other maps have globals, but they're not constant.
And I can't upload .j to the forums, so [del]here's[/del] a mediafire link.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Well then..
I guess that's all it takes.

Although we'll never know the real cause now! muahahahaha.
:nuts:


EDIT: Just by the way.
I did have the newest NewGen and JASSHelper before.
So I don't know what caused it.
 
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