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 poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    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] Module question

Discussion in 'Triggers & Scripts' started by Krogoth, Aug 1, 2013.

  1. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Here is library used:
    Code (vJASS):
    //===============
    //=== Indexed ===
    //=== v0.900 ====

    library Indexed requires Indexer
        //Timers
        module ObtainTimerIndex
            set Assist.workInteger = 0
            loop
                exitwhen t[Assist.workInteger] == Assist.workTimer
                set Assist.workInteger = Assist.workInteger + 1
            endloop
        endmodule
        module ObtainLargeTimerIndex
            set Assist.workInteger = 0
            loop
                exitwhen T[Assist.workInteger] == Assist.workTimer
                set Assist.workInteger = Assist.workInteger + 1
            endloop
        endmodule

        //Units
        module ObtainUnitIndex
            set Assist.workInteger = 0
            loop
                exitwhen u[Assist.workInteger] == Assist.workUnit
                set Assist.workInteger = Assist.workInteger + 1
            endloop
        endmodule
       
        module SeekUnitBegin
            set Assist.workInteger = 0
            loop
                exitwhen Assist.workInteger == IndexCount(indexer)
                if u[Assist.workInteger] == Assist.workUnit then
        endmodule
        module SeekUnitEnd
                    return
                endif
                set Assist.workInteger = Assist.workInteger + 1
            endloop
        endmodule
    endlibrary

    There are SeekUnitBegin and SeekUnitEnd

    Here is the main code:
    Code (vJASS):
    //===================
    //=== AttackDelay ===
    //===== v1.000 ======

    library AttackDelay requires Assist, Indexed, Orders
    //=== Settings ===
    globals
        private constant integer ABILCODE = 'X211'
        private constant string ORDER = "magicleash"
        private constant string SFX = "AttackDelay.mdl"
        private constant string SFX_ATTACH_POINT = "origin"
    //----------------
        private constant real COOLDOWN = 1.7
    endglobals
    //================
        function UnitApplyAttackDelay takes unit u, real delay, real duration returns nothing
            call AttackDelay.apply(u, delay, duration)
        endfunction

        struct AttackDelay extends array
            private static integer indexer
            private static unit array u
            private static real array delay
            private static boolean array slow
            private static timer array T
            private static timer array t
            private static unit array caster
            private static method onInit takes nothing returns nothing
                set indexer = CreateIndexer()
            endmethod
           
            private static method end takes nothing returns nothing
                set Assist.workTimer = GetExpiredTimer()
                implement ObtainLargeTimerIndex
                call Deindex(indexer, Assist.workInteger)
                set u[Assist.workInteger] = null
                set caster[Assist.workInteger] = null
                call BJDebugMsg("END " + I2S(Assist.workInteger))
                call PauseTimer(t[Assist.workInteger])
            endmethod

            static method apply takes unit u, real delay, real duration returns nothing
                set Assist.workInteger = Index(indexer)
                set thistype.u[Assist.workInteger] = u
                set thistype.delay[Assist.workInteger] = delay
                set slow[Assist.workInteger] = true
                if T[Assist.workInteger] == null then
                    set T[Assist.workInteger] = CreateTimer()
                    set t[Assist.workInteger] = CreateTimer()
                endif
                call BJDebugMsg("APPLY " + I2S(Assist.workInteger))
                call TimerStart(T[Assist.workInteger], duration, false, function thistype.end)
            endmethod

            static method onUnitIssuedOrder takes nothing returns nothing
                set Assist.workUnit = GetTriggerUnit()
                implement SeekUnitBegin
                    if GetIssuedOrderId() != ORDER_ATTACK + ORDERS_OFFSET and caster[Assist.workInteger] != null then
                        call BJDebugMsg("FREE " + I2S(Assist.workInteger))
                        call RemoveUnit(caster[Assist.workInteger])
                        set caster[Assist.workInteger] = null
                    endif
                implement SeekUnitEnd
            endmethod

            private static method cooldown takes nothing returns nothing
                set Assist.workTimer = GetExpiredTimer()
                implement ObtainTimerIndex
                set slow[Assist.workInteger] = true
            endmethod

            static method onAttack takes nothing returns nothing
                set Assist.workUnit = GetAttacker()

            set Assist.workInteger = 0
            loop
                exitwhen Assist.workInteger == IndexCount(indexer)
                if u[Assist.workInteger] == Assist.workUnit then
                    if slow[Assist.workInteger] then
                        set slow[Assist.workInteger] = false
                        call BJDebugMsg("ATTACK " + I2S(Assist.workInteger))
                        call DestroyEffect(AddSpecialEffectTarget(SFX, Assist.workUnit, SFX_ATTACH_POINT))
                        call TimerStart(t[Assist.workInteger], COOLDOWN, false, function thistype.cooldown)
                        set caster[Assist.workInteger] = CastUnit(u[Assist.workInteger], u[Assist.workInteger], delay[Assist.workInteger], ABILCODE, 1, ORDER)
                    endif
                    return
                endif
                set Assist.workInteger = Assist.workInteger + 1
            endloop
               
               
                /*implement SeekUnitBegin
                    if slow[Assist.workInteger] then
                        set slow[Assist.workInteger] = false
                        call BJDebugMsg("ATTACK " + I2S(Assist.workInteger))
                        call DestroyEffect(AddSpecialEffectTarget(SFX, Assist.workUnit, SFX_ATTACH_POINT))
                        call TimerStart(t[Assist.workInteger], COOLDOWN, false, function thistype.cooldown)
                        set caster[Assist.workInteger] = CastUnit(u[Assist.workInteger], u[Assist.workInteger], delay[Assist.workInteger], ABILCODE, 1, ORDER)
                    endif
                implement SeekUnitEnd*/

            endmethod        
        endstruct
    endlibrary
    Take a look at onAttack
    Exactly same thing written manually works properly, but implemented (right below) does not.
    (Both compilated)

    (Problem with return? Wrong module use?)
     
  2. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Okay, I replaced it with some better code, and it works
    But why this got compilated if such implementing is broken
     
  3. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    *After reading the tutorial
    Still a question: why compiled?
     
  4. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    That kind of implementing works. I'm not sure what your question is.

    It may have some occasional issues when you reference a variable or something like that, but it should work fine. What errors do you get?
     
  5. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    When I implemented one module 2 times inside methods, system does not work. I guess, first time it's implemented, second time - not. But if change this to 2 similar modules, it works.
    (*No actual errors, just like no code)