| 09-19-2007, 01:01 AM | #1 |
Basically I have a problem with Dynamic Arrays (using vJASS) and it seems to be a weird one. Simply put when retrieving data from a certain function from the 2 dimeansional dynamic array it always returns 0.4. JASS:type arrayability extends real array[cas_abilitylimit] type arraylevel extends arrayability array[cas_levellimit] globals integer array AbilityIndex boolean array AbilityStored integer MaxAbility = 0 arraylevel a endglobals function BeginAttackSpeedBonusInitialization takes nothing returns nothing set a = arraylevel.create() endfunction function RegisterAbilityAttackSpeedBonusLevel takes integer abilityid, integer level, real amount returns nothing //local arraylevel a=arraylevel.create() local string id = I2S(abilityid) if GetStoredBoolean(cas_cache,"abilitystorage",id) != true then set MaxAbility = MaxAbility + 1 call StoreBoolean(cas_cache,"abilitystorage",id,true) set AbilityIndex[MaxAbility] = abilityid endif set a[MaxAbility][level] = amount endfunction function GetUnitAttackSpeed takes unit u returns real //local arraylevel a=arraylevel.create() local string id = UnitId2String(GetUnitTypeId(u)) local real cooldown = GetStoredReal(cas_cache,id,"cooldowntime") local real amount = 0 local integer counter = 1 local integer abilityid local integer level set amount = amount + (GetHeroAgi(u,true) * cas_agilitybonus) loop exitwhen counter > MaxAbility set level = GetUnitAbilityLevel(u,AbilityIndex[counter]) if GetUnitAbilityLevel(u,AbilityIndex[counter]) > 0 then call BJDebugMsg(R2S(a[counter][level])) endif set amount = amount + a[counter][level] set counter = counter + 1 endloop return cooldown/(1 + (amount * 0.01)) endfunction function RegisterAbilityAttackSpeedBonus takes integer abilityid, real amount returns nothing call RegisterAbilityAttackSpeedBonusLevel(abilityid,1,amount) endfunction function FinishAttackSpeedBonusInitialization takes nothing returns nothing call FlushStoredMission(cas_cache,"abilitystorage") endfunction I have highlighted the line thats the problem, it seems no matter what the value the counter is or what level it is, a[counter][level] always retrieves 0.4 from the array. Even when the arrays are defined locally it makes no difference and retrieving the data from other triggers and functions work fine, its just this one that is the problem, here is the trigger that stores them JASS:function Trig_Item_Configuration_Actions takes nothing returns nothing call BeginAttackSpeedBonusInitialization() //<-- Specify when Initialization begins call RegisterAbilityAttackSpeedBonus('AIsx',0.15) //Item Attack Speed Bonus - Glove of Haste call RegisterAbilityAttackSpeedBonus('AIs2',0.20) //Item Attack Speed Bonus Greater - Gloves of Haste call RegisterAbilityAttackSpeedBonusLevel('BHtc',1,-0.50) //ThunderClap (Level 1) call RegisterAbilityAttackSpeedBonusLevel('BHtc',2,-0.50) //ThunderClap (Level 2) call RegisterAbilityAttackSpeedBonusLevel('BHtc',3,-0.50) //ThunderClap (Level 3) call RegisterAbilityAttackSpeedBonus('Bslo',-0.25) //Slow call RegisterAbilityAttackSpeedBonus('Bbsk',0.50) //Beserk call RegisterAbilityAttackSpeedBonus('Bblo',0.40) //Bloodlust call RegisterAbilityAttackSpeedBonus('Bliq',-0.80) //Liquid Fire call RegisterAbilityAttackSpeedBonusLevel('BOae',2,0.05) //Endurance Aura (Level 1) call RegisterAbilityAttackSpeedBonusLevel('BOae',2,0.10) //Endurance Aura (Level 2) call RegisterAbilityAttackSpeedBonusLevel('BOae',3,0.15) //Endurance Aura (Level 3) call RegisterAbilityAttackSpeedBonus('Bcri',-0.50) //Cripple call RegisterAbilityAttackSpeedBonus('Buhf',0.75) //Unholy Frenzy call RegisterAbilityAttackSpeedBonus('Bspo',-0.25) //Slow Poison call RegisterAbilityAttackSpeedBonus('Bfzy',0.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 I have done testing and the data is stored without problems, retrieving the data from the array in this function creates no problems, its just in the GetUnitAttackSpeed function that I get incorrect data. Any ideas what the problem is? |
| 09-19-2007, 03:15 AM | #2 |
JASS:function BeginAttackSpeedBonusInitialization takes nothing returns nothing local integer i=1 set a = arraylevel.create() loop exitwhen i<=cas_levellimit set a[i]=arrayability.create() set i=i+1 endloop endfunction |
| 09-19-2007, 04:40 AM | #3 |
Thanks heaps, didnt know you needed to initialize it that way |
