HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Another Problem With Dynamic Arrays

10-15-2007, 11:55 PM#1
PandaMine
I have another problem with global dynamic arrays (vJASS), it seems in different functions the arrays retrieve a different value then stored. This how only starts happening after the first index has exceeded a value. As can be seen with the highlighted lines, the call BJDebugMsg(R2S(a[8][1])) in RegisterAbilityAttackSpeedBonusLevel retrieves the proper value (80) where as the call BJDebugMsg(R2S(a[8][1])) in GetUnitAttackSpeed retrieves 40. Every value retrieved after and including the [8] first dimeansion index in the GetUnitAttackSpeed is always 40, where as if its retrieved in RegisterAbilityAttackSpeedBonusLevel its the correct value

Any ideas about why its always retrieving 40 in the other function? Here is the code, oh BTW the limit for both indexes is 1000 (so that is not an issue)

Collapse JASS:
globals
private integer array AbilityIndex
private boolean array AbilityStored
private integer MaxAbility = 0
private arraylevel a
endglobals

function BeginAttackSpeedBonusInitialization takes nothing returns nothing
local integer counter = 0
call HashtableCAS_a.init()
set a = arraylevel.create()
loop
exitwhen counter >= CAS_levellimit
set a[counter] = arrayability.create()
set counter = counter + 1
endloop
endfunction

function RegisterAbilityAttackSpeedBonusLevel takes integer abilityid, integer level, real amount returns nothing
if HashtableCAS_a.get(abilityid) != 1 then
set MaxAbility = MaxAbility + 1
call HashtableCAS_a.put(abilityid,1)
if MaxAbility == 11 then
call BJDebugMsg(R2S(a[8][1]))
endif
set AbilityIndex[MaxAbility] = abilityid
endif
set a[MaxAbility][level] = amount
endfunction

function RegisterAbilityAttackSpeedBonus takes integer abilityid, real amount returns nothing
call RegisterAbilityAttackSpeedBonusLevel(abilityid,1,amount)
endfunction

function FinishAttackSpeedBonusInitialization takes nothing returns nothing
call HashtableCAS_a.clear()
endfunction

function GetUnitAttackSpeed takes unit u returns real
local attackprojectiledata ap = HashtableCAS_u.get(GetUnitTypeId(u))
local real cooldown = ap.cooldowntime
local real amount = 0
local integer counter = 0
local integer abilityid
local integer level
set amount = amount + (GetHeroAgi(u,true) * CAS_agilitybonus)
call BJDebugMsg(R2S(a[8][1]))
loop
exitwhen counter == MaxAbility 
set level = GetUnitAbilityLevel(u,AbilityIndex[counter])
set amount = amount + a[counter][level]
set counter = counter + 1
endloop
return cooldown * (100/(100 + amount)) 
endfunction

And here is the confugarition trigger
Collapse JASS:
function Trig_Item_Configuration_Actions takes nothing returns nothing
call BeginAttackSpeedBonusInitialization() //<-- Specify when Initialization begins
call RegisterAbilityAttackSpeedBonus('AIsx',15) //Item Attack Speed Bonus - Glove of Haste
call RegisterAbilityAttackSpeedBonus('AIs2',20) //Item Attack Speed Bonus Greater - Gloves of Haste
call RegisterAbilityAttackSpeedBonusLevel('BHtc',1,-50) //ThunderClap (Level 1)
call RegisterAbilityAttackSpeedBonusLevel('BHtc',2,-50) //ThunderClap (Level 2)
call RegisterAbilityAttackSpeedBonusLevel('BHtc',3,-50) //ThunderClap (Level 3)
call RegisterAbilityAttackSpeedBonus('Bslo',-25) //Slow
call RegisterAbilityAttackSpeedBonus('Bbsk',50) //Beserk
call RegisterAbilityAttackSpeedBonus('Bblo',40) //Bloodlust
call RegisterAbilityAttackSpeedBonus('Bliq',80) //Liquid Fire
call RegisterAbilityAttackSpeedBonusLevel('BOae',1,5) //Endurance Aura (Level 1)
call RegisterAbilityAttackSpeedBonusLevel('BOae',2,10) //Endurance Aura (Level 2)
call RegisterAbilityAttackSpeedBonusLevel('BOae',3,15) //Endurance Aura (Level 3)
call RegisterAbilityAttackSpeedBonus('Bcri',-50) //Cripple
call RegisterAbilityAttackSpeedBonus('BUhf',75) //Unholy Frenzy
call RegisterAbilityAttackSpeedBonus('Bspo',-25) //Slow Poison
call RegisterAbilityAttackSpeedBonus('Bfzy',40) //Frenzy
//Need to do slowed (frost attack/frost armor/frost nova)

call FinishAttackSpeedBonusInitialization() //<-- Need to specify when we finish adding abilities
//to clear some memory
endfunction

//===========================================================================
function InitTrig_Ability_Configuration takes nothing returns nothing
    set gg_trg_Ability_Configuration = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Ability_Configuration, 1 )
    call TriggerAddAction( gg_trg_Ability_Configuration, function Trig_Item_Configuration_Actions )
endfunction
10-16-2007, 02:40 AM#2
PandaMine
I figured it out, it was a problem with the limits, when I changed them to 100/100 it worked fine (must have been an issue with instances)
10-16-2007, 03:10 AM#3
Vexorian
- Indentation is your friend.
- You say something about vJass dynamic arrays but I see no declaration of them.
10-16-2007, 11:18 AM#4
PandaMine
I missed that when posting the code. The only reason I dont indent is tab doesnt work in world editor, its damn annoying. I got used to reading unindented code anyways

EDIT: in regards to indenting, teSH to the rescue :D