Page 1 of 1

[DotP2013] Spell Rupture

PostPosted: 20 Mar 2013, 13:37
by BETenner
I'm trying to coding Spell Rupture, I couldn't find any problem in my code, but it leads to a crash (not script error) while loading the card.
Please help me find the cause..

Code: Select all
  <SPELL_ABILITY filter_zone="ZONE_IN_PLAY">
    <TARGET_DEFINITION id="0">
      local filter = Object():GetFilter()
      filter:Clear()
      filter:SetZone( ZONE_STACK )
      filter:SetStackObjectType( STACK_OBJECT_CARD )
      filter:SetHint( HINT_ENEMY_ONLY, EffectController() )
    </TARGET_DEFINITION>
    <TARGET_DETERMINATION>
      return AtLeastOneTargetFromDefinition(0)
    </TARGET_DETERMINATION>
    <PLAY_TIME_ACTION target_choosing="1">
      EffectController():ChooseTarget( 0, "CARD_QUERY_CHOOSE_SPELL_TO_COUNTER", EffectDC():Make_Targets(0) )
    </PLAY_TIME_ACTION>
    <RESOLUTION_TIME_ACTION>
      local filter = Object():GetFilter()
      filter:Clear()
      filter:AddCardType(CARD_TYPE_CREATURE)
      filter:SetController(EffectController())
      filter:SetZone(ZONE_IN_PLAY)
      local count = filter:EvaluateObjects()
      local maxpower = 0
      for i=0,count-1 do
        local crt = filter:GetNthEvaluatedObject(i)
        if (crt ~= nil) then
          if (crt:GetCurrentCharacteristics():Power_Get() &gt; maxpower) then
            maxpower = crt:GetCurrentCharacteristics():Power_Get()
          end
        end
      end
      EffectDC():Set_Int(1, maxpower)
    </RESOLUTION_TIME_ACTION>
    <RESOLUTION_TIME_ACTION>
      local target_spell = EffectDC():Get_Targets(0):Get_CardPtr(0)
      local player = target_spell:GetPlayer()
      local maxpower = EffectDC():Get_Int(1)
      if player ~= nil then
         if player:CanAfford("{"..maxpower.."}") == 1 then
            player:BeginNewMultipleChoice()   
            player:AddMultipleChoiceAnswer( "CARD_QUERY_OPTION_YES" )   
            player:AddMultipleChoiceAnswer( "CARD_QUERY_OPTION_NO" )   
            player:AskMultipleChoiceQuestion( "CARD_QUERY_ASK_PAY_FOR_SPELL_RUPTURE" )
         end
      end
    </RESOLUTION_TIME_ACTION>
    <RESOLUTION_TIME_ACTION>
      local target_spell = EffectDC():Get_Targets(0):Get_CardPtr(0)
      local player = target_spell:GetPlayer()
      local maxpower = EffectDC():Get_Int(1)
      local decision = Object():GetMultipleChoiceResult()
      if player ~= nil then
        if player:CanAfford("{"..maxpower.."}") == 1 then
          if decision ~= 1 then
            player:TapLand("{"..maxpower.."}")
          else
             target_spell:CounterSpell()
          end
        else
          target_spell:CounterSpell()
        end
      end
    </RESOLUTION_TIME_ACTION>
  </SPELL_ABILITY>

Re: [DotP2013] Spell Rupture

PostPosted: 20 Mar 2013, 13:56
by thefiremind
I can't find a sure reason for that, but as first thing to try I would enclose the "for" loop in an "if count &gt; 0 then", and the last 2 RESOLUTION_TIME_ACTIONs in an "if target_spell ~= nil then". You also forgot filter:NotTargetted() when looking for the greatest power (it can't be the reason of the crash, but the card is wrong without it).

If it still crashes, you can try to find the greatest power in another way:
Code: Select all
    local player = EffectController()
    local maxpower = 0
    local filter = Object():GetFilter()
    filter:Clear()
    filter:AddCardType( CARD_TYPE_CREATURE )
    filter:SetZone( ZONE_IN_PLAY )
    filter:SetController( player )
    filter:NotTargetted()
    local any_creature = filter:CountStopAt(1)
    if any_creature == 1 then
       maxpower = -1
       while filter:CountStopAt(1) == 1 do
          maxpower = maxpower + 1
          filter:SetPowerMin( maxpower+1 )
       end
       -- now "maxpower" is equal to the greatest power
    end
This is how I do in Triumph of Ferocity. The filter functions that begin with "Set" overwrite their previous state when called, so the thing works without clearing and re-setting the whole filter.

Re: [DotP2013] Spell Rupture

PostPosted: 20 Mar 2013, 14:15
by BETenner
I did all you said, now it won't crash again, thanks...again(xN)!