It is currently 20 Aug 2019, 16:00
   
Text Size

[DotP2013] Spell Rupture

Moderators: Xander9009, CCGHQ Admins

[DotP2013] Spell Rupture

Postby BETenner » 20 Mar 2013, 13:37

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>
BETenner
 
Posts: 36
Joined: 07 Mar 2013, 14:20
Has thanked: 7 times
Been thanked: 4 times

Re: [DotP2013] Spell Rupture

Postby thefiremind » 20 Mar 2013, 13:56

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.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 717 times

Re: [DotP2013] Spell Rupture

Postby BETenner » 20 Mar 2013, 14:15

I did all you said, now it won't crash again, thanks...again(xN)!
BETenner
 
Posts: 36
Joined: 07 Mar 2013, 14:20
Has thanked: 7 times
Been thanked: 4 times


Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 2 guests


Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 10 minutes)
Most users ever online was 287 on 31 Mar 2019, 04:11

Users browsing this forum: No registered users and 2 guests

Login Form