1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[vJASS] Trigger array does not wanna work

Discussion in 'Triggers & Scripts' started by Krogoth, Jul 24, 2013.

  1. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    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
     
  2. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    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 ?
     
  3. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    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.
     
  4. Luorax

    Luorax

    Joined:
    Aug 7, 2009
    Messages:
    1,301
    Resources:
    1
    Maps:
    1
    Resources:
    1
    You should post the code, maybe there's something you're doing wrong but do no notice.
     
  5. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    I feel sorry about the code, it's kinda lame, but ok =D
    Look at "contact", here is dat compare (no "B" message)

    Code (vJASS):
    //===========================
    //=== 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:
    Code (vJASS):
    //=======================
    //==== 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
     
  6. Cataract92

    Cataract92

    Joined:
    May 25, 2009
    Messages:
    100
    Resources:
    0
    Resources:
    0
    What do you get in the
    Code (vJASS):
    call BJDebugMsg("SUICIDE "+I2S(Assist.workInteger))

    in the commitSuicide-method?
    Maybe there is something wrong with the indexing when you create the trigger
     
  7. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Suicide 0
     
  8. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    One thing to try is that instead of having the function callback in the "filter" part of TriggerRegisterUnitInRange(), here:
    Code (vJASS):
    call TriggerRegisterUnitInRange(t[Assist.workInteger], target, 350, function thistype.contact)

    Try putting it as a separate condition:
    Code (vJASS):
    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.
     
  9. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    ^ Wow, thanks!
    I will check it later, but you absolutely right about GetTriggerUnit(), I used separate conditions already, but in this case forget to. :O
    This seems to be the solution