| 10-20-2007, 07:46 AM | #1 |
Hey, I'm trying to get a stat modifier working. The idea is, every time you call the function, it increases the attack speed or decreases the attack speed. However, it seems to skip directly to the highest speed, or directly to the lowest speed. I can't seem to tell why, can anyone? JASS:globals integer array AttackSpeedId endglobals function IncreaseAttackSpeed takes unit u returns integer local integer I if(GetUnitAbilityLevel(u, AttackSpeedId[9]) == 1)then //Remove decreasers. set I = 9 loop if(GetUnitAbilityLevel(u, AttackSpeedId[i]) == 1)then call UnitRemoveAbility(u, AttackSpeedId[i]) endif exitwhen(I == 16) set I = I + 1 endloop endif set I = 1 loop if(GetUnitAbilityLevel(u, AttackSpeedId[i]) == 0)then call UnitAddAbility(u, AttackSpeedId[i]) return 1 endif exitwhen(I == 8) set I = I + 1 endloop return 0 endfunction function DecreaseAttackSpeed takes unit u returns integer local integer I if(GetUnitAbilityLevel(u, AttackSpeedId[1]) == 1)then //Remove increasers. set I = 1 loop if(GetUnitAbilityLevel(u, AttackSpeedId[i]) == 1)then call UnitRemoveAbility(u, AttackSpeedId[i]) endif exitwhen(I == 8) set I = I + 1 endloop endif set I = 9 loop if(GetUnitAbilityLevel(u, AttackSpeedId[i]) == 0)then call UnitAddAbility(u, AttackSpeedId[i]) return 1 endif exitwhen(I == 16) set I = I + 1 endloop return 0 endfunction function InitAttackSpeedId takes nothing returns nothing set AttackSpeedId[0] = 0 set AttackSpeedId[1] = 'A007' //1 set AttackSpeedId[2] = 'A008' set AttackSpeedId[3] = 'A009' set AttackSpeedId[4] = 'A00A' set AttackSpeedId[5] = 'A00B' set AttackSpeedId[6] = 'A00C' set AttackSpeedId[7] = 'A00D' set AttackSpeedId[8] = 'A00E' //128 set AttackSpeedId[9] = 'A00F' //-1 set AttackSpeedId[10] = 'A00G' set AttackSpeedId[11] = 'A00H' set AttackSpeedId[12] = 'A00I' set AttackSpeedId[13] = 'A00J' set AttackSpeedId[14] = 'A00K' set AttackSpeedId[15] = 'A00L' set AttackSpeedId[16] = 'A00M' //-128 endfunction Well thanks for any help, this is a weird glitch. |
| 10-20-2007, 08:11 AM | #2 |
please use the jass tags Code:
[jass]call PolledWait(1.00)[/jass] JASS:call PolledWait(1.00) |
| 10-22-2007, 05:31 AM | #3 |
I'm not sure if this is causing your problem, but I think it's a bad practice to not have the first or last line of your loop be "exitwhen". That might just be my personal opinion though. Why not rewrite the functions like so? JASS:function ChangeAttackSpeed takes unit u , integer change returns integer local integer I = 1 loop if(GetUnitAbilityLevel(u, AttackSpeedId[i]) == 1)then call UnitAddAbility(u, AttackSpeedId[I + change]) call UnitRemoveAbility(u, AttackSpeedId[i] return 1 endif set I = I + 1 exitwhen I == 17 endloop // At this point, we've gone through the loop and they have no attack speed modifier. I would probably call UnitAddAbility(u, AttackSpeed[9] but it's up to you. return 0 endfunction function IncreaseAttackSpeed takes unit u returns integer return ChangeAttackSpeed(u, 1) endfunction function DecreaseAttackSpeed takes unit u returns integer return ChangeAttackSpeed(u, -1) endfunction The way it worked before, calling decrease attack speed once removed ALL attack speed buffs. It seems to make more sense to me that decrease attack speed would only decrease the change by 1. Also, my method assumes that you only want them to have 1 attack modifying ability at a time (your old one worked differently). Does this help solve your problem? |
| 10-22-2007, 06:50 AM | #4 |
Not really what I was looking for. I have it increase attack speed by a power of 2 (1, 2, 4, 8, 16) and it componds attack speed, so you end up with +31 at 5. But this implementation (minus the removing the last added ability) still adds all the ability buffs (-255% and +255 reguardless of how many you had.) Still not sure why though. |
| 10-22-2007, 07:38 AM | #5 |
I != i...mostly. Except sometimes when JASS gets confused. That shouldn't even compile. |
| 10-22-2007, 02:44 PM | #6 |
Oh...good eye Griffin. Yeah - I follow why you'd want that functionality. Let me say just once more though that once you get that current implementation working, calling DecreaseAttackSpeed even once will remove all of your increased attack speed. That's fine if that's the functionality you're hoping for. |
| 10-22-2007, 04:58 PM | #7 | |
Quote:
exitwhen at the start is definitely fine (it's a while loop). exitwhen is useful in the middle of a loop for checking that some iterator statement worked correctly: JASS:set g = some_group loop set u = FirstOfGroup(g) exitwhen u == null call GroupRemoveUnit(g, u) //do stuff with u endloop instead of JASS:set g = some_group set u = FirstOfGroup(g) if (u != null) then loop call GroupRemoveUnit(g, u) //do stuff with u set u = FirstOfGroup(g) exitwhen u == null endloop endif It's also useful for breaking out of the loop on secondary conditions, like when you're trying to find a unit with a specific property. JASS:set g = some_group loop set u = FirstOfGroup(g) exitwhen u == null call GroupRemoveUnit(g, u) if (u matches some condition) then exitwhen true endif endloop if (u != null) then //we found a matching unit else //no matching unit endif But you have to be very careful to COMMENT this type of code! |
| 10-24-2007, 12:23 AM | #8 |
I have a similar function on my "Defend the bunker" map. Every time the unit attacks, his attack speed goes up and after 3 seconds of non-attacking, it resets. I never had a problem where the attack speed would just automatically go to the fastest or slowest one. |
