• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Trigger array does not wanna work

Status
Not open for further replies.
Level 7
Joined
Apr 5, 2011
Messages
245
What reasons can be?

(I mean, I go to set t[0] = CreateTrigger() bla bla bla, then compare GetTriggeringTrigger() with t[0] when trigger proces and fail.
More than that, t[1] == GetTriggeringTrigger() !
WTF?)

Btw, timer array always works for me
 
Level 7
Joined
Apr 5, 2011
Messages
245
to compare triggers u need to use a global trigger array. not a local trigger array.
the gettriggeringtrigger can be put into a local trigger but when u try to compare it to a local trigger it returns null because that local variable is a local.
why are u trying to do it like this ?
Nope, I use global. I put new trigger in t[0], then wait until it proces, compare with GetTriggeringTrigger() and get wrong. 2 different events, how could I do it with local?

This seems like Blizzard bug!

Added:
To be concrete, I use static trigger array inside the struct. Creating and then destroying it.
 
Level 7
Joined
Apr 5, 2011
Messages
245
I feel sorry about the code, it's kinda lame, but ok =D
Look at "contact", here is dat compare (no "B" message)

JASS:
//===========================
//=== SpellPredatorSpirit ===
//========= v1.000 ==========

library SpellPredatorSpirit requires Assist, Cast, SpellSpiritScout, Teams

//=== Settings ===
globals
    private constant integer ABILCODE = 'X122'
    private constant integer SFX_ABILITY = 'X123'
    private constant string SFX_ABILITY_ORDER = "bloodlust"
//----------------
    private constant real DETONATE_RANGE = 100
    private constant real CASTER_LIFETIME = 1
endglobals
    struct SpellPredatorSpirit extends array
        private static real array AOE
        static if LIBRARY_ManaLoss then
            private static real array MANA_COST
        endif
        private static method onInit takes nothing returns nothing
            set AOE[1] = 12000
            set AOE[2] = 1600
            set AOE[3] = 2000
            static if LIBRARY_ManaLoss then
                set MANA_COST[1] = 80
                set MANA_COST[2] = 80
                set MANA_COST[3] = 80
            endif
//================
            set selfdestruct = selfdestruct.create()
        endmethod
        readonly static integer abilcode = ABILCODE
        
        private static unit target
        private static indexCarrier selfdestruct
        private static unit array spirit
        private static trigger array t[10]
        
        private static method contact takes nothing returns boolean
            local trigger t = GetTriggeringTrigger()
            set Assist.workInteger = 0
            call BJDebugMsg("A")
            
            if thistype.t[0] == GetTriggeringTrigger() then
                call BJDebugMsg("YES")
            endif
            
            loop
                exitwhen thistype.t[Assist.workInteger] == t
                call BJDebugMsg("FUCK")
                set Assist.workInteger = Assist.workInteger + 1
            endloop
            call BJDebugMsg(I2S(Assist.workInteger))
            set Assist.workUnit = GetTriggerUnit()
            if Assist.workUnit == UnitData.Unit[GetUnitUserData(spirit[Assist.workInteger])] then
            call BJDebugMsg("B")
                set Assist.workInteger = 0
                call selfdestruct.unregister(Assist.workInteger)
                set spirit[Assist.workInteger] = null
                set thistype.t[Assist.workInteger] = null
                call DealDamage(UnitData.Unit[Assist.workInteger], Assist.workUnit, 99999, PURE)
                call DestroyTrigger(t)
            endif
            set t = null
            return false
        endmethod
        
        private static method commitSuicide takes nothing returns nothing
            call IssueTargetOrder(target, "move", UnitData.Unit[Assist.workInteger])
            call TimedLife.apply(target, INFINITE)
            call CastUnit(Assist.workUnit, target, CASTER_LIFETIME, SFX_ABILITY, 1, SFX_ABILITY_ORDER)
            set Assist.workInteger = selfdestruct.register()
            set spirit[Assist.workInteger] = target
            set t[Assist.workInteger] = CreateTrigger()
            call BJDebugMsg("SUICIDE "+I2S(Assist.workInteger))
            call TriggerRegisterUnitInRange(t[Assist.workInteger], target, 350, function thistype.contact)
            if t[1] != null then
                call BJDebugMsg("DAFUQ")
            endif
        endmethod
        
        static method onSpellEffect takes nothing returns nothing
            local unit u
            set Assist.workInteger = GetSpellAbilityId()
            if Assist.workInteger == ABILCODE then
                set Assist.workPlayer = GetTriggerPlayer()
                set Assist.workUnit = GetTriggerUnit()
                set target = GetSpellTargetUnit()
                set Assist.workInteger = GetUnitUserData(target)
                if UnitData.Unit[Assist.workInteger] == null then
                    set u = GetClosestUnit(GetUnitX(target), GetUnitY(target), AOE[GetUnitAbilityLevel(Assist.workUnit, ABILCODE)], function SpellSpiritScout.closestHeroFilter)
                    if u != null then
                        set UnitData.Unit[Assist.workInteger] = u
                        call commitSuicide()
                    endif
                else
                    call commitSuicide()
                endif
                set u = null
                set target = null
            elseif Assist.workInteger == SFX_ABILITY then
                call UnitAddAbility(GetSpellTargetUnit(), 'Avul')
            endif
        endmethod
    endstruct
endlibrary
IndexCarrier:
JASS:
//=======================
//==== IndexCarrier =====
//======= v1.000 ========

library IndexCarrier
//=== Settings ===
    globals
        private constant integer SIZE_LIMIT = 1024
        private constant integer TOTAL_SIZE_LIMIT = 32768
//----------------
        private constant integer NO_FUNCTION = -1
    endglobals
//================
    function interface integer_void takes integer index returns nothing
    
    struct indexCarrier[TOTAL_SIZE_LIMIT]
        readonly integer count = 0
        private boolean array registered[SIZE_LIMIT]
        private integer freeIndex_count = 0
        private integer array freeIndex[SIZE_LIMIT]
        private integer_void unregister_func = NO_FUNCTION

        static method init takes integer_void unregister_func returns indexCarrier
            local indexCarrier i = indexCarrier.create()
            set i.unregister_func = unregister_func
            return i
        endmethod
        
        method operator[] takes integer index returns boolean
            return registered[index]
        endmethod
        
        method register takes nothing returns integer
            local integer index
            if freeIndex_count > 0 then
                set freeIndex_count = freeIndex_count - 1
                set index = freeIndex[freeIndex_count]
            else
                set index = count
                set count = count + 1
            endif
            set registered[index] = true
            return index
        endmethod
            
        method unregister takes integer index returns boolean
            if registered[index] != null then
                set registered[index] = false
                set freeIndex[freeIndex_count] = index
                set freeIndex_count = freeIndex_count + 1
                call unregister_func.execute(index)
                return true
            endif
            return false
        endmethod
    endstruct
endlibrary
 
Level 4
Joined
May 25, 2009
Messages
100
What do you get in the
JASS:
call BJDebugMsg("SUICIDE "+I2S(Assist.workInteger))
in the commitSuicide-method?
Maybe there is something wrong with the indexing when you create the trigger
 
One thing to try is that instead of having the function callback in the "filter" part of TriggerRegisterUnitInRange(), here:
JASS:
call TriggerRegisterUnitInRange(t[Assist.workInteger], target, 350, function thistype.contact)
Try putting it as a separate condition:
JASS:
call TriggerRegisterUnitInRange(t[Assist.workInteger], target, 350, null)
call TriggerAddCondition(t[Assist.workInteger], Condition(function thistype.contact))

Perhaps that is related to the issue. I don't remember if GetTriggeringTrigger()/GetTriggerUnit() works when you put it in the filter function for the event registry. I'm guessing GetTriggeringTrigger() returns null, and since t[1] is null they return true when you try to check if they're equal. The rest of the function probably doesn't work because GetTriggerUnit() is returning null as well. Change it like I did above and perhaps it will work.
 
Status
Not open for further replies.
Top