• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Just want to know . . .

Status
Not open for further replies.
Level 10
Joined
Sep 3, 2009
Messages
458
. . . If this code works properly.

JASS:
       private static method CheckInstance takes string abilityName returns thistype
           local integer i = 1
           loop
               exitwhen i > TOTAL
               set datu = AAC_ARRAY[i]
               if datu.abilityName[i] == abilityName then
                  call BJDebugMsg( datu.abilityName[i] + " = " + abilityName)
                  set i = TOTAL + 1
               else
                  call BJDebugMsg( datu.abilityName[i] + " != " + abilityName)
                  set i = i + 1
                  set datu = 0
               endif
           endloop
           call BJDebugMsg("datu = " + I2S(datu))
           return datu
       endmethod

because for some reason it does not go to this line here:

JASS:
                  call BJDebugMsg( datu.abilityName[i] + " = " + abilityName)
                  set i = TOTAL + 1

even if datu.abilityName == abilityName is true.

I just can't figure this thing out.
 
Level 10
Joined
Sep 3, 2009
Messages
458
Lol I thought you'd say that. Ima post the library.

JASS:
//============================================================================================
// A A C (Add Ability Charge) System v.0.1 
// By neku99
//============================================================================================

library AAC initializer init
    globals
    
        private integer array AAC_ARRAY[8190]
        private integer array AAC_ABIL_ID
        
        private integer TOTAL       = 0
        private timer AAC_TIMER    = CreateTimer()
        
        private constant real TICK  = 0.1
        
    endglobals
    
    struct check
    
       private unit u = null
       private real cool
       private integer slot      
       private integer charge    
       private integer abilityID
       private string array abilityName[8190]
                
       private static thistype data
       private static thistype datu
       
       private static method CheckInstance takes string abilityName returns thistype
           local integer i = 1
           loop
               exitwhen i > TOTAL
               set datu = AAC_ARRAY[i]
               if datu.abilityName[i] == abilityName then
                  call BJDebugMsg( datu.abilityName[i] + " = " + abilityName)
                  set i = TOTAL + 1
               else
                  call BJDebugMsg( datu.abilityName[i] + " != " + abilityName)
                  set i = i + 1
                  set datu = 0
               endif
           endloop
           call BJDebugMsg("datu = " + I2S(datu))
           return datu
       endmethod
       
       private static method Loop takes nothing returns nothing
           local integer i = 1
           set data = AAC_ARRAY[i]

           loop
               exitwhen i > TOTAL
               if data.charge > 0 then
                  //call BJDebugMsg("data.abilityID[" + I2S(i) + "] = " + I2S(data.abilityID))
               else
                  if not((GetUnitAbilityLevel( data.u, AAC_ABIL_ID[data.slot])) > 0) then
                     call UnitRemoveAbility( data.u, data.abilityID )
                     call UnitAddAbility( data.u, AAC_ABIL_ID[data.slot])
                  endif
                  
                  if data.cool > 1.00 then
                     set data.cool = data.cool - TICK
                  else
                     call UnitRemoveAbility( data.u, AAC_ABIL_ID[data.slot])
                     call UnitAddAbility( data.u, data.abilityID )
                     set AAC_ARRAY[i] = AAC_ARRAY[TOTAL]
                     set TOTAL = TOTAL - 1
                     set i = i - 1
                     
                     call BJDebugMsg("END")
                     call data.destroy()

                     
                  endif
               endif
               set i = i + 1
           endloop
       endmethod
       
       static method create takes unit u, real cool, integer slot, integer charge, integer abilityID, string abilityName returns thistype
       
           set TOTAL = TOTAL + 1
           
           if (CheckInstance(abilityName) == 0) then
           
              call BJDebugMsg("NEW INSTANCE")
              set data             = allocate()
              set data.u           = u
              set data.cool        = cool
              set data.slot        = slot
              set data.charge      = charge - 1
              set data.abilityID   = abilityID
              set data.abilityName[TOTAL] = abilityName
              
              set AAC_ARRAY[TOTAL] = data
              
               call UnitRemoveAbility( u, abilityID )
               call UnitAddAbility( u, abilityID )
               call DestroyEffect(AddSpecialEffectLoc( "Abilities\\Weapons\\Bolt\\BoltImpact.mdl", GetUnitLoc(u)))
           else
                call BJDebugMsg("UPDATE INSTANCE")
                call UnitRemoveAbility( datu.u, datu.abilityID)
                call UnitAddAbility( datu.u, datu.abilityID)
                set datu.charge = datu.charge - 1
                set datu = AAC_ARRAY[TOTAL]
                set TOTAL = TOTAL - 1
           endif
           
            if TOTAL == 1 then
                call BJDebugMsg("START TIMER")
                call TimerStart( AAC_TIMER, TICK, true, function check.Loop)
            endif
            return data       
       endmethod
       
    endstruct
    
    private function init takes nothing returns nothing
    
        set AAC_ABIL_ID[1] = 'A00A'
        set AAC_ABIL_ID[2] = 'A00B'
        set AAC_ABIL_ID[3] = 'A00D'
        set AAC_ABIL_ID[4] = 'A007'
        
    endfunction
endlibrary

I put some debug messages to determine if a method was running. I use CheckInstance to check if an ability used by the unit is still looping. If it still looping update the charges of that instance. If not create a new instance. Hope this'll help. Thank you for the trouble :)

EDIT: I once used abilityID to determine the instance but it didn't work. So I made a abilityName to check instance but didn't work too. I think the code is bugged somewhere. But couldn't find it ever since last night.
 
Level 10
Joined
Sep 3, 2009
Messages
458
hmmmm ok ima do that.

EDIT: Well I just figured that my approach to the code could be better. And I just realized that unless I redo everything I won't fix this issue. So ima recode it as I found a better way (I think) to do this.

Thanks bribe and purplepoot for posting something to help yeah :D +rep!
 
Last edited:
Status
Not open for further replies.
Top