HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Code go boom :(

08-27-2009, 08:13 PM#1
darkwulfv
Okay, so here's some code that has decided to cause a no-error-message game crash.

Collapse JASS:
scope LuminousArrows

globals
  private integer ABILITY_ID = 'A02Q'
  private integer BUFF_ID = 'B00Z'
  private integer DUMMY_ID = 'A02N'
endglobals

private constant function DAMAGE takes integer lvl returns real
  return 4. + (lvl * 2.)
endfunction

private function Conditions takes nothing returns boolean
  return GetUnitAbilityLevel(GetTriggerDamageSource(), ABILITY_ID) > 0
endfunction

private function Actions takes nothing returns nothing
  local unit u = GetTriggerDamageSource()
  local unit u2 = GetTriggerDamageTarget()
  local integer lvl = GetUnitAbilityLevel(u, ABILITY_ID)
  
 // call PolledWait(.2)
  
  if GetUnitAbilityLevel(u2, BUFF_ID) > 0 and GetUnitAbilityLevel(u2, 'B010') < 1 then
    call IssueTargetOrder(CreateDummyUnit(GetOwningPlayer(u), 'e000', GetUnitX(u2), GetUnitY(u2), DUMMY_ID, lvl, true), "faeriefire", u2)
    call UnitDamageTargetEx(u, u2, ArmorDamage(u2, DAMAGE(lvl), DAMAGE_TYPE_DAY, true), ATTACK_TYPE_CHAOS, DAMAGE_TYPE_DAY, true)
  endif
  
  set u = null
  set u2 = null
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
    call TriggerRegisterDamageEvent(t, 1)
    set t = null
endfunction

endscope

Notes:
*This uses Rising_Dusk's IDDS, which works fine in other code.
*ArmorDamage(...) is just a function I made to calculate damage. It works in other code fine.
*CreateDummyUnit(...) is just a wrapper function I made for my own purposes.
*This fires off of an arrow attack; basically, a unit is hit, it checks for the buff, and casts a spell. Should work fine and dandy, right?


Can anyone see why it goes boom? Probably something silly, but it crashes as soon as it should fire (when a unit is hit). It's not the arrow ability itself, as nothing bad happens when I turn it off.
08-27-2009, 09:15 PM#2
Zerzax
Think about it for a second - you register damage. When the event fires, you damage again. The event fires because you dealt damage. You deal damage. The event fires because you dealt damage. You deal damage... you can see where this is going. Just put a conditional to stop it from looping forever.
08-27-2009, 09:17 PM#3
Rising_Dusk
Yes, you are creating an infinite trigger loop. Notice that you deal damage inside of a damage event response. This means that the trigger fires itself forever. If you want to make this work there are a few ways to do so:
  • Add a check that GetTriggerDamageType() != DAMAGE_TYPE_DAY so that it does not trigger on the bonus damage your ability deals.
  • Before you call UnitDamageTargetEx, put in call DisableTrigger(GetTriggeringTrigger()) and after the UnitDamageTargetEx call, put in call EnableTrigger(GetTriggeringTrigger())
Either solution will work, what really matters is the behavior you are looking for. (Do you want the spell to trigger on DAY damage or not, basically)
08-27-2009, 09:29 PM#4
darkwulfv
Oh wow, how did I not realize that. I knew it'd be something silly. Thanks, I'll fix it pronto.