It is currently 07 Sep 2025, 21:43
   
Text Size

Need help fixing a custom card

Moderator: CCGHQ Admins

Re: Need help fixing a custom card

Postby Xander9009 » 16 Mar 2014, 20:22

RiiakShiNal wrote:This is probably because I forgot to tell you to put a TOKEN_REGISTRATION block in for the manager token on each card using the custom characteristics (it has been a while since I last used/looked at them). #-o
Code: Select all
   <TOKEN_REGISTRATION reservation="1" type="RSN_TOKEN_CHARACTERISTIC_MANAGER" />
Hopefully I won't forget it next time. [-o<

Xander9009 wrote:EDIT: I don't expect you guys to read through all of this, but I'm going to go ahead and post the code of all 6 cards that are using this code so far. That way if you know something specific that might cause it, you can glance through for that in particular.

Note that as far as the ability code goes, the five creatures are all identical except for which ability they grant. So if you look at Fleetfoot, you've looked at all the rest (barring mistakes).
  • Book of Shards - confirmed missing the above TOKEN_REGISTRATION.
  • Fleetfoot - confirmed missing the above TOKEN_REGISTRATION.
  • Garlith - confirmed missing the above TOKEN_REGISTRATION.
  • League's Assassin - confirmed missing the above TOKEN_REGISTRATION.
  • League's Healer - confirmed missing the above TOKEN_REGISTRATION.
  • Windcrafter Drake - confirmed missing the above TOKEN_REGISTRATION.

Note that I only skimmed through the code looking to see if the TOKEN_REGISTRATION was there as that is the highly likely suspect.
I added in the line you provided near the end (where the other token registrations are for the Book of Shards and in the same relative position for the others) but I still got a crash when I player the third creature. Also, of note, just generally, it seems to happen when I play the three in quick succession. Not sure why that would matter, but just in case. And just for confirmation, I'm still not using a custom token manager, so it shouldn't be that I'm missing a second registration.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby RiiakShiNal » 18 Mar 2014, 14:23

Xander9009 wrote:I added in the line you provided near the end (where the other token registrations are for the Book of Shards and in the same relative position for the others) but I still got a crash when I player the third creature. Also, of note, just generally, it seems to happen when I play the three in quick succession. Not sure why that would matter, but just in case. And just for confirmation, I'm still not using a custom token manager, so it shouldn't be that I'm missing a second registration.
I put all of your cards into XML files (and a LOL file with "X_CHARACTERISTIC_LEGION = 90090001"), added the missing TOKEN_REGISTRATION which I already stated, put all of them into a 5 colour deck with Archangel of Thune (base game), Ornithopter (base game), Voice of All (thefiremind), Arcane Sanctum, Blackcleave Cliffs, Copperline Gorge, Darkslick Shores, Razorverge Thicket, and Seachrome Coast (all lands are from my mod). I tried the deck out in game against a dumb test deck (no offensive capability so that I have all the time in the world to test cards) and played for 30-40 turns, cast multiple copies of all 6 of your cards, performed multiple attacks with your cards, tried all abilities and everything worked with no crashes. I played 3 more games under the same conditions still no crashes.

Given my results I can only think of these possibilities (at this moment):
  • You missed adding the TOKEN_REGISTRATION I said to one of the 6 cards (or misspelled something on one or more of them).
  • You changed the cards other than adding the TOKEN_REGISTRATION I mentioned since you last posted them in a way that is leading to the crashes.
  • Some other card in your deck is causing the crashes and is unrelated to the 6 you posted.
  • A card in your opponent's deck is causing the crashes and is unrelated to the 6 you posted.
  • You are playing online matches which have proven to be buggy with mods (even when all players have the same mods) and then it is probably a synchronization issue or some other equally difficult to reproduce problem.

Other notes:
  • It seems that you intended the Legion characteristic to act only on Legion creatures you control (much like the new slivers) so in that case Book of Shards probably shouldn't give itself the Charge counter Sunburst (especially since it can't use the counters because it doesn't get the mana ability).
  • Your cards seem to be a bit over-powered (casting cost) considering their abilities are like the new slivers (you can look at them for ideas on what your casting costs should be in relation).
  • Since your creatures are much like slivers another route you could have taken instead of custom characteristics could have been adding a new sub-type (though that would have implications with other cards like Coat of Arms). A new sub-type can be implemented with relatively little code (and no TOKEN_REGISTRATIONs), but can currently conflict with other mods that add or alter sub-types (official sub-types or otherwise).
  • Technically TOKEN_REGISTRATIONS can go anywhere in the card as long as it is a child of the CARD_V2 tag. Most people put them towards the bottom of the card to make them easier to find or simply as a convention. I tend to put them below the related ability blocks (makes it easier to copy the ability blocks to other cards because I can copy the blocks and the TOKEN_REGISTRATIONs at the same time).
RiiakShiNal
Programmer
 
Posts: 2188
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: Need help fixing a custom card

Postby Xander9009 » 18 Mar 2014, 19:02

RiiakShiNal wrote:I put all of your cards into XML files (and a LOL file with "X_CHARACTERISTIC_LEGION = 90090001"), added the missing TOKEN_REGISTRATION which I already stated, put all of them into a 5 colour deck with Archangel of Thune (base game), Ornithopter (base game), Voice of All (thefiremind), Arcane Sanctum, Blackcleave Cliffs, Copperline Gorge, Darkslick Shores, Razorverge Thicket, and Seachrome Coast (all lands are from my mod). I tried the deck out in game against a dumb test deck (no offensive capability so that I have all the time in the world to test cards) and played for 30-40 turns, cast multiple copies of all 6 of your cards, performed multiple attacks with your cards, tried all abilities and everything worked with no crashes. I played 3 more games under the same conditions still no crashes.

Given my results I can only think of these possibilities (at this moment):
  • You missed adding the TOKEN_REGISTRATION I said to one of the 6 cards (or misspelled something on one or more of them).
  • You changed the cards other than adding the TOKEN_REGISTRATION I mentioned since you last posted them in a way that is leading to the crashes.
  • Some other card in your deck is causing the crashes and is unrelated to the 6 you posted.
  • A card in your opponent's deck is causing the crashes and is unrelated to the 6 you posted.
  • You are playing online matches which have proven to be buggy with mods (even when all players have the same mods) and then it is probably a synchronization issue or some other equally difficult to reproduce problem.
I'm not sure why I was getting the crashes, then. All I changed that I remember was copying and pasting the line you posted into the cards. My best guess is that it's your 2nd point; I changed something else without remembering/realizing it. I checked for the first point, and they all had the registration. I tried the deck with only these cards, so it wasn't intereference from within my deck. The opponents were all vanilla decks, so that probably wasn't it. And I wasn't playing online, so that one definitely isn't it. But changing something either by accident or just without remembering it seems fairly likely. I'll copy the code I posted and restart from there (haven't changed anything, so it'll be easy enough). Thank you for taking the time to test them.

RiiakShiNal wrote:Other notes:
  • It seems that you intended the Legion characteristic to act only on Legion creatures you control (much like the new slivers) so in that case Book of Shards probably shouldn't give itself the Charge counter Sunburst (especially since it can't use the counters because it doesn't get the mana ability).
  • Your cards seem to be a bit over-powered (casting cost) considering their abilities are like the new slivers (you can look at them for ideas on what your casting costs should be in relation).
  • Since your creatures are much like slivers another route you could have taken instead of custom characteristics could have been adding a new sub-type (though that would have implications with other cards like Coat of Arms). A new sub-type can be implemented with relatively little code (and no TOKEN_REGISTRATIONs), but can currently conflict with other mods that add or alter sub-types (official sub-types or otherwise).
  • Technically TOKEN_REGISTRATIONS can go anywhere in the card as long as it is a child of the CARD_V2 tag. Most people put them towards the bottom of the card to make them easier to find or simply as a convention. I tend to put them below the related ability blocks (makes it easier to copy the ability blocks to other cards because I can copy the blocks and the TOKEN_REGISTRATIONs at the same time).
I thought using a creature type might be easier, and I thought about that in particular because the ability is inspired largely by allies and slivers. I don't remember the reason I decided to go with a characteristic, but if it would possibly conflict with other cards, then I'll stick with the code that's already working.

For the sunburst artifact, it's supposed to be able to give colorless mana. I might have messed that up, but I haven't messed with that since fixing it so at least not everything (including lands, even) had the ability, so I didn't notice. The creatures only grant their abilities to other creatures simply because only creatures should have those abilities. The sunburst and mana production should be on anything with a legion ability of its own.

As for being over-powered, they're very over-powered so far because I haven't yet put in any of the things that limit them. They were just to make sure the code would work to begin with. I fully intend to limit them and make them more balanced, so no worries there. I'm not sure exactly what I'm going to go with, but so far, if it works well, I'm thinking of a twist on cumulative upkeep that's not quite as expensive. Until I can play the deck, I won't know if that'll be enough, but we'll see.

And finally, for where to put the token registrations, I too prefer your placement. That's why I had them there. I had them right by the manager token creation code.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby Xander9009 » 27 Apr 2014, 21:02

So, I've been away playing Dragon Age, but I'm back. And yesterday and today I finished up 40 of my 42 custom cards. I realized why I didn't go with creature type; I wanted to give the ability to artifacts as well (and now it extends to a land and some instants and sorceries).

Anyway, I've got a couple of questions for my last two custom cards. The cards are rather complex and I'm not even certain one of them can be done. First, the cards:
Name: ?
Cost: {4}
Type: Artifact
Abilities:
  • Imprint - When this permanent enters the battlefield, you may exile target non-land permanent you control from the battlefield or target instant or sorcery card from your hand with converted mana cost less than or equal to this permanent's converted mana cost.
  • This creature gets +X/+X where X is the exiled permanent's converted mana cost.
  • {X}, {T}: Copy exiled instant or sorcery, where X is this permanent's converted mana cost. You may cast the copy without paying its mana cost.
These aren't worded exactly. But basically, whenever a permanent enters the battlefield under your control and it has a legion ability, then that permanent (*imprinter*) will give you the option to exile a permanent you control or an instant/sorcery from your hand (*imprintee*). Only cards with a CMC <= *imprinter's* CMC can be targeted. If *imprinter* is a creature and *imprintee* is a permanent, *imprintee* gets +X/+X where X is *imprintee's* CMC. If *imprintee* is an instant/sorcery, then *imprinter* can pay *imprintee's* CMC and tap itself to cast a copy of *imprintee*.

(Whew! That's a bit complex...) The problem is this: how can I make a card that's entering the battlefield gain the imprint ability and exile the card? The rest is fairly easy, but I don't know for sure how to go about having *imprinter* perform the ability.

Second up (this one's simpler, I promise)...
Name: ?
Cost: {B}{R}{G}
Type: Creature
Abilities: Dredge X, where X is this card's converted mana cost. (so each card in your graveyard with legion has this ability).

The problem is that Dredge goes by the card names and they're all hard-coded. I'm not sure how to go about granting it. I know I'll need to convert the dredge code. But I wonder if it would be better to simply have this creature scan the graveyard for legion abilities and work from there, or if I should go to the trouble of making another fake characteristic for dredge and granting that. So, this one I should be able to do (or at least mostly), but I just want an outside opinion or two about which way would be better to grant a dredge ability.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby RiiakShiNal » 27 Apr 2014, 22:09

Well, first off the two cards you listed don't have Legion (or you left it off of the abilities list for each card) and thus would not be affected by legion at least by the way you have both described and implemented it.

Xander9009 wrote:Abilities:

Imprint - When this permanent enters the battlefield, you may exile target non-land permanent you control from the battlefield or target instant or sorcery card from your hand with converted mana cost less than or equal to this permanent's converted mana cost.
This creature gets +X/+X where X is the exiled permanent's converted mana cost.
{X}, {T}: Copy exiled instant or sorcery, where X is this permanent's converted mana cost. You may cast the copy without paying its mana cost.

These aren't worded exactly. But basically, whenever a permanent enters the battlefield under your control and it has a legion ability, then that permanent (*imprinter*) will give you the option to exile a permanent you control or an instant/sorcery from your hand (*imprintee*). Only cards with a CMC <= *imprinter's* CMC can be targeted. If *imprinter* is a creature and *imprintee* is a permanent, *imprintee* gets +X/+X where X is *imprintee's* CMC. If *imprintee* is an instant/sorcery, then *imprinter* can pay *imprintee's* CMC and tap itself to cast a copy of *imprintee*.
Based on how the abilities are worded then I'm pretty sure the words I bolded are wrong.
  • Why would you give an exiled card +X/+X?
  • If X is "this permanent's converted mana cost" then why would you pay the exiled card's cost instead of the cost of the card in play with the ability?

Xander9009 wrote:The problem is this: how can I make a card that's entering the battlefield gain the imprint ability and exile the card? The rest is fairly easy, but I don't know for sure how to go about having *imprinter* perform the ability.
You would probably need to apply the ability to the permanent before or during the zone change. As such you would probably need to use a TRIGGERED_ABILITY with TRIGGER value ZONECHANGE_BEGIN or ZONECHANGE_TRANSITION that applies the ability to the card with Legion through a CONTINUOUS_ACTION with a DURATION that ends once it enters ZONE_BATTLEFIELD (at which point your normal Legion applying code should work properly).

Xander9009 wrote:The problem is that Dredge goes by the card names and they're all hard-coded. I'm not sure how to go about granting it. I know I'll need to convert the dredge code. But I wonder if it would be better to simply have this creature scan the graveyard for legion abilities and work from there, or if I should go to the trouble of making another fake characteristic for dredge and granting that. So, this one I should be able to do (or at least mostly), but I just want an outside opinion or two about which way would be better to grant a dredge ability.
With Dredge you have a couple of options:
  1. Write Dredge functions that will accept a Dredge value.
  2. Implement Dredge as a custom int-based Characteristic and grant that.

If you choose option 1 then you can simply grant the Ability with the appropriate Dredge value (constant value or a value based on a value of the card receiving the Dredge ability such as CMC or P/T). This will be virtually impossible to implement the single Dredge choice with allowing you to potentially dredge multiple cards a turn.

If you choose option 2 then your best bet would be to make a Manager token for the Dredge characteristic and base the Dredge value on the characteristic value. This way you can simply assign the characteristic value based on a constant or some card based value (either from the granting card or the receiving card). This would probably be easier to implement the single Dredge choice with.

Regardless of which method you choose you should be aware that it will conflict other Dredge implementations (no single Dredge choice) unless you implement using option 2 and rewrite all the other Dredge cards to use the new characteristic.
RiiakShiNal
Programmer
 
Posts: 2188
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: Need help fixing a custom card

Postby Xander9009 » 28 Apr 2014, 00:14

RiiakShiNal wrote:Well, first off the two cards you listed don't have Legion (or you left it off of the abilities list for each card) and thus would not be affected by legion at least by the way you have both described and implemented it.
Yeah, I copied these from my spreadsheet, and on the spreadsheet, I didn't bother writing "Legion: " into every ability. I forgot to add that in.

RiiakShiNal wrote:Based on how the abilities are worded then I'm pretty sure the words I bolded are wrong.
  • Why would you give an exiled card +X/+X?
  • If X is "this permanent's converted mana cost" then why would you pay the exiled card's cost instead of the cost of the card in play with the ability?
The first one was typed incorrectly, but the second was actually correct. However, you have a good point, and I'll change that around.

RiiakShiNal wrote:You would probably need to apply the ability to the permanent before or during the zone change. As such you would probably need to use a TRIGGERED_ABILITY with TRIGGER value ZONECHANGE_BEGIN or ZONECHANGE_TRANSITION that applies the ability to the card with Legion through a CONTINUOUS_ACTION with a DURATION that ends once it enters ZONE_BATTLEFIELD (at which point your normal Legion applying code should work properly).
Alright. I didn't think it would work properly because of the card changing zones mid way through, but I'll give this a shot.

RiiakShiNal wrote:With Dredge you have a couple of options:
  1. Write Dredge functions that will accept a Dredge value.
  2. Implement Dredge as a custom int-based Characteristic and grant that.

If you choose option 1 then you can simply grant the Ability with the appropriate Dredge value (constant value or a value based on a value of the card receiving the Dredge ability such as CMC or P/T). This will be virtually impossible to implement the single Dredge choice with allowing you to potentially dredge multiple cards a turn.

If you choose option 2 then your best bet would be to make a Manager token for the Dredge characteristic and base the Dredge value on the characteristic value. This way you can simply assign the characteristic value based on a constant or some card based value (either from the granting card or the receiving card). This would probably be easier to implement the single Dredge choice with.

Regardless of which method you choose you should be aware that it will conflict other Dredge implementations (no single Dredge choice) unless you implement using option 2 and rewrite all the other Dredge cards to use the new characteristic.
Yeah, I was wondering how I was going to go about making this work without conflicting with the other. I can think of one or two ways which might work without having to recode all the other dredge cards, but it wouldn't really be worth the effort. After searching for abilities I haven't used yet, I think I'm going to switch to something that's easier and which won't conflict with things. I'll probably go with retrace or devour.

Thanks for the advice.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby Xander9009 » 30 Apr 2014, 19:59

Okay, so I did decide to switch from dredge, and now it's using retrace and is working fine. Imprint's still got a couple issues, but I'm still trying to figure it out. But I have a couple things that just aren't making sense to me.

First question is about LinkedDC(). I've got a card that grants cipher to instants and sorceries I cast. Unfortunately, it always fails at the last second. The card is exiled and nailed to the creature. When the creature does combat damage to a player, I'm asked if I want to cast the encoded spell. Unfortunately, choosing yes doesn't actually do anything. I was getting some errors, so my attempts to fix those led to the discovery that LinkedDC() is nil. I don't know how I'm supposed to fix that or what would cause it. The error was pointing me to the duration block, of which there's only one. The nil value error only stopped when I inserted the "if LinkedDC() ~= nil then" line (and corresponding "end"). I'm still getting another nil error in a resolution block or two, but as long as LinkedDC() is nil, nothing else will work. Here's the code:

| Open
Code: Select all
<STATIC_ABILITY>
   <FILTER filter_id="0">
      local filter = ClearFilter()
      filter:SetZone( ZONE_STACK )
      filter:Add( FE_CONTROLLER, OP_IS, EffectController() )
      local subFilter = filter:AddSubFilter_Or()
         subFilter:Add( FE_TYPE, OP_IS, CARD_TYPE_INSTANT )
         subFilter:Add( FE_TYPE, OP_IS, CARD_TYPE_SORCERY )
   </FILTER>
   <CONTINUOUS_ACTION layer="6" filter_id="0">
      if FilteredCard() ~= nil and RSN_Characteristics_Get( FilteredCard(), X_CHARACTERISTIC_LEGION ) then
         FilteredCard():GetCurrentCharacteristics():GrantAbility(0)
      end
   </CONTINUOUS_ACTION>
</STATIC_ABILITY>
<SPELL_ABILITY resource_id="0" linked_ability_group="1">
   <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Cipher]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[Cryptage]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Cifrar.]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Chiffrieren]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Cifrare]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[暗号]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[암호문]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Шифр]]></LOCALISED_TEXT>
   <LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Cifrar]]></LOCALISED_TEXT>
   <RESOLUTION_TIME_ACTION>
      local filter = ClearFilter()
      filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
      filter:Add(FE_CONTROLLER, OP_IS, EffectController() )
      if EffectSource():IsToken() == false then
         EffectController():ChooseItem( "CARD_QUERY_CHOOSE_A_CARD_TO_ENCODE_ONTO", EffectDC():Make_Targets(1), QUERY_FLAG_MAY )
      end
   </RESOLUTION_TIME_ACTION>
   <RESOLUTION_TIME_ACTION>
      local cipherDC = EffectDC():Get_Targets(1)
      if cipherDC ~= nil then
         local chosenCard = cipherDC:Get_CardPtr(0)
         if chosenCard ~= nil then
            local effectSource = EffectSource()
            if (effectSource ~= nil) then
               effectSource:Exile()
               effectSource:NailOnto(chosenCard)
               LinkedDC():Set_CardPtr(0, effectSource)
            end
         end
      end
   </RESOLUTION_TIME_ACTION>
   <CONTINUOUS_ACTION layer="6">
      local chosenCardDC = EffectDC():Get_Targets(1)
      if chosenCardDC ~= nil then
         local chosencard = chosenCardDC:Get_CardPtr(0)
         if chosencard ~= nil then
            local characteristics = chosencard:GetCurrentCharacteristics()
            characteristics:GrantAbility(1)
            chosencard:AddScore(150)
         end
      end
   </CONTINUOUS_ACTION>
   <DURATION>
      if LinkedDC() ~= nil then
         EffectController():GainLife(1)
         if LinkedDC():Get_CardPtr(0) ~= nil then
            EffectController():GainLife(2)
            local chosenCardDC = EffectDC():Get_Targets(1)
            if chosenCardDC ~= nil and chosenCardDC:Get_CardPtr(0) ~= nil then
               return false
            end
         end
      end
      return true
   </DURATION>
</SPELL_ABILITY>
<TRIGGERED_ABILITY resource_id="1" linked_ability_group="1">
   <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Whenever this creature deals combat damage to a player, you may copy the Ciphered card and cast the copy without paying its mana cost.]]></LOCALISED_TEXT>
   <TRIGGER value="SOURCE_DEALS_DAMAGE_TO_PLAYER" simple_qualifier="self" damage_type="combat" />
   <RESOLUTION_TIME_ACTION>
      local encodedSpell = LinkedDC():Get_CardPtr(0)
      if encodedSpell ~= nil then
         local copy = EffectController():CopySpell( encodedSpell )
         if copy ~= nil then
            if EffectController():CanCastSpellForFree(copy) then
               EffectController():CastSpellForFree(copy)
            end
         else
            EffectControll():GainLife(1)
         end
      else
         EffectControll():GainLife(1)
      end
   </RESOLUTION_TIME_ACTION>
   <MAY tag="CARD_QUERY_WOULD_YOU_LIKE_TO_CAST_ENCODED_SPELL" always_prompt="1" />
</TRIGGERED_ABILITY>
Second has to do EffectDC():Get_Targets(0) returning a value, being counted, and then suddenly being nil. Does Count() remove the targets or something? In the following ability (it's only half of it) I only get 3 life (just for debugging) when I try to sacrifice one creature. I should be getting more than that. The code exits when it checks if EffectDC():Get_Targets(0) is nil again. It checked before without any problem, but at that point it returns nil.

| Open
Code: Select all
<ACTIVATED_ABILITY>
   <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Sacrifice up to 5 permanents with legion: Search your library for a card with legion whose colors consist only of the colors of the exiled permanents and whose converted mana cost is less than or equal to the total converted mana cost of sacrificed permanents..]]></LOCALISED_TEXT>
   <COST type="Generic">
      <PREREQUISITE>
         MTG():ClearFilterMark()
         local filter = ClearFilter()
         filter:Add( FE_IS_PERMANENT, true )
         filter:Add( FE_CONTROLLER, OP_IS, EffectController() )
         filter:Add( FE_CMC, OP_GREATER_THAN_OR_EQUAL_TO, 1 )
         local count = filter:EvaluateObjects()
         for i=0,count-1 do
            if filter:GetNthEvaluatedObject(i) ~= nil and RSN_Characteristics_Get( filter:GetNthEvaluatedObject(i), X_CHARACTERISTIC_LEGION ) == true then
               return true
            end
         end
         return false
      </PREREQUISITE>
      <RESOLUTION_TIME_ACTION>
         if EffectController() ~= nil then
            MTG():ClearFilterMark()
            local filter = ClearFilter()
            filter:Add( FE_IS_PERMANENT, true )
            filter:Add( FE_CONTROLLER, OP_IS, EffectController() )
            local count = filter:EvaluateObjects()
            for i=0,count-1 do
               if filter:GetNthEvaluatedObject(i) ~= nil and RSN_Characteristics_Get( filter:GetNthEvaluatedObject(i), X_CHARACTERISTIC_LEGION ) == true then
                  filter:GetNthEvaluatedObject(i):MarkForFilter()
               end
            end
            filter:SetMarkedObjectsOnly()
            EffectController():SetItemCount( 5 )
            for i=0,4 do
               EffectController():SetItemPrompt(i, "CARD_QUERY_CHOOSE_PERMANENT_SACRIFICE" )
            end       
            EffectController():ChooseItems( EffectDC():Make_Targets(0), QUERY_FLAG_UP_TO )
         end
      </RESOLUTION_TIME_ACTION>
      <RESOLUTION_TIME_ACTION>
         if EffectDC():Get_Targets(0) ~= nil then
         EffectController():GainLife(1)
            local count = EffectDC():Get_Targets(0):Count()
            if count &gt; 0 then
            EffectController():GainLife(1)
               EffectDC():Set_Int(0, 0)
               EffectDC():Set_Int(1, 0)
               EffectDC():Set_Int(2, 0)
               EffectDC():Set_Int(3, 0)
               EffectDC():Set_Int(4, 0)
               local totalCMC = 0
               for i=0,count-1 do
               EffectController():GainLife(1)
                  if EffectDC():Get_Targets(0) ~= nil then
                  EffectController():GainLife(1)
                     local card = EffectDC():Get_Targets(0):Get_CardPtr(i)
                     if card ~= nil then
                     EffectController():GainLife(1)
                        if card:GetColour():GetNumColours() &gt; 0 then
                           if card:GetColour():Test( COLOUR_WHITE ) == true then
                              EffectDC():Set_Int(0, 1)
                           end
                           if card:GetColour():Test( COLOUR_BLUE ) == true then
                              EffectDC():Set_Int(1, 1)
                           end
                           if card:GetColour():Test( COLOUR_BLACK ) == true then
                              EffectDC():Set_Int(2, 1)
                           end
                           if card:GetColour():Test( COLOUR_RED ) == true then
                              EffectDC():Set_Int(3, 1)
                           end
                           if card:GetColour():Test( COLOUR_GREEN ) == true then
                              EffectDC():Set_Int(4, 1)
                           end
                        end
                        totalCMC = totalCMC + card:GetConvertedManaCost()
                        card:GetPlayer():Sacrifice(card)
                     end
                  end
               end
               EffectDC():Set_Int(5, totalCMC)
            end
         end
      </RESOLUTION_TIME_ACTION>
   </COST>
Last, and most confusingly, I can't figure out why my game keeps crashing. Unlike before, it's a consistent crash, but I can't figure out what's going on. Basically, it was working fine before, but now, if I have a creature on the battlefield and I summon another, then the game crashes. This happened even when I put just two cards alone in a deck (with my test card, which I haven't changed at all). Play one: fine. Play the other: crash immediately. The only thing that stopped the crashes was changing the casting cost to {1}. This isn't restricted to the two cards I used in my test deck, though. Any of my new cards will do it. I've even had it happen with base cards, which tells me it's nothing to do with the cards themselves. More testing revealed the second card I cast doesn't even have to be a creature, anything will prompt it. I'm at a loss at this point. The thing is, I stripped them down to the following:
| Open
Code: Select all
<?xml version='1.0' encoding='UTF-8'?>
<CARD_V2 ExportVersion="1">
   <FILENAME text="SELESNYA_EMISSARY_90090014" />
   <CARDNAME text="SELESNYA_EMISSARY" />
   <TITLE>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Selesnya Emissary]]></LOCALISED_TEXT>
   </TITLE>
   <MULTIVERSEID value="90090014" />
   <ARTID value="90090014" />
   <ARTIST name="James Ryman" />
   <CASTING_COST cost="{W}{G}" />
   <FLAVOURTEXT>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[The Selesnya are famed for their ability to raise an army from nothing.]]></LOCALISED_TEXT>
   </FLAVOURTEXT>
   <TYPE metaname="Creature" />
   <SUB_TYPE metaname="Cleric" />
   <EXPANSION value="RTR" />
   <RARITY metaname="C" />
   <POWER value="2" />
   <TOUGHNESS value="2" />
</CARD_V2>
and the other card was similarly stripped down, but with a different cost. The moment I try playing one while the other is already out, it crashes. Is there some bug I didn't know about? Or is the deck builder (I'm using yours) possibly messing up the deck colors or something? I wouldn't expect so, but I can't think of why this would happen. I thought it might have been a memory issue, but restarting the computer didn't fix it, so it's not something stuck in the memory; and task manager shows the game using less than half a gig of ram and it never drastically changes.

Sorry for the long post, but I'm completely confused by these.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby RiiakShiNal » 30 Apr 2014, 21:17

Xander9009 wrote:First question is about LinkedDC(). I've got a card that grants cipher to instants and sorceries I cast. Unfortunately, it always fails at the last second. The card is exiled and nailed to the creature. When the creature does combat damage to a player, I'm asked if I want to cast the encoded spell. Unfortunately, choosing yes doesn't actually do anything. I was getting some errors, so my attempts to fix those led to the discovery that LinkedDC() is nil. I don't know how I'm supposed to fix that or what would cause it. The error was pointing me to the duration block, of which there's only one. The nil value error only stopped when I inserted the "if LinkedDC() ~= nil then" line (and corresponding "end"). I'm still getting another nil error in a resolution block or two, but as long as LinkedDC() is nil, nothing else will work.
I'm not seeing anything obviously wrong with your code. However, I believe the problem may be in granting the Cipher ability to another card and then trying to access the LinkedDC() .Card A grants Cipher to Card B then Card B gets nailed onto Card C and grants Card C the TRIGGERED_ABILITY so does the LinkedDC refer to the LinkedDC of Card A or Card B, I think this is where the engine gets confused. In that case you may need to use an ObjectDC to get around the issue.

Xander9009 wrote:Second has to do EffectDC():Get_Targets(0) returning a value, being counted, and then suddenly being nil. Does Count() remove the targets or something? In the following ability (it's only half of it) I only get 3 life (just for debugging) when I try to sacrifice one creature. I should be getting more than that. The code exits when it checks if EffectDC():Get_Targets(0) is nil again. It checked before without any problem, but at that point it returns nil.
Count() should not remove the targets, but you could always try putting the target chest into a variable to access it later.

| Open
Code: Select all
<ACTIVATED_ABILITY>
   <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Sacrifice up to 5 permanents with legion: Search your library for a card with legion whose colors consist only of the colors of the exiled permanents and whose converted mana cost is less than or equal to the total converted mana cost of sacrificed permanents..]]></LOCALISED_TEXT>
   <COST type="Generic">
      <PREREQUISITE>
         MTG():ClearFilterMark()
         local filter = ClearFilter()
         filter:Add( FE_IS_PERMANENT, true )
         filter:Add( FE_CONTROLLER, OP_IS, EffectController() )
         filter:Add( FE_CMC, OP_GREATER_THAN_OR_EQUAL_TO, 1 )
         local count = filter:EvaluateObjects()
         for i=0,count-1 do
            if filter:GetNthEvaluatedObject(i) ~= nil and RSN_Characteristics_Get( filter:GetNthEvaluatedObject(i), X_CHARACTERISTIC_LEGION ) == true then
               return true
            end
         end
         return false
      </PREREQUISITE>
      <RESOLUTION_TIME_ACTION>
         if EffectController() ~= nil then
            MTG():ClearFilterMark()
            local filter = ClearFilter()
            filter:Add( FE_IS_PERMANENT, true )
            filter:Add( FE_CONTROLLER, OP_IS, EffectController() )
            local count = filter:EvaluateObjects()
            for i=0,count-1 do
               if filter:GetNthEvaluatedObject(i) ~= nil and RSN_Characteristics_Get( filter:GetNthEvaluatedObject(i), X_CHARACTERISTIC_LEGION ) == true then
                  filter:GetNthEvaluatedObject(i):MarkForFilter()
               end
            end
            filter:SetMarkedObjectsOnly()
            EffectController():SetItemCount( 5 )
            for i=0,4 do
               EffectController():SetItemPrompt(i, "CARD_QUERY_CHOOSE_PERMANENT_SACRIFICE" )
            end       
            EffectController():ChooseItems( EffectDC():Make_Targets(0), QUERY_FLAG_UP_TO )
         end
      </RESOLUTION_TIME_ACTION>
      <RESOLUTION_TIME_ACTION>
         if EffectDC():Get_Targets(0) ~= nil then
            local targets = EffectDC():Get_Targets(0)
         EffectController():GainLife(1)
            local count = targets:Count()
            if count &gt; 0 then
            EffectController():GainLife(1)
               EffectDC():Set_Int(0, 0)
               EffectDC():Set_Int(1, 0)
               EffectDC():Set_Int(2, 0)
               EffectDC():Set_Int(3, 0)
               EffectDC():Set_Int(4, 0)
               local totalCMC = 0
               for i=0,count-1 do
               EffectController():GainLife(1)
                  if targets ~= nil then
                  EffectController():GainLife(1)
                     local card = targets:Get_CardPtr(i)
                     if card ~= nil then
                     EffectController():GainLife(1)
                        if card:GetColour():GetNumColours() &gt; 0 then
                           if card:GetColour():Test( COLOUR_WHITE ) == true then
                              EffectDC():Set_Int(0, 1)
                           end
                           if card:GetColour():Test( COLOUR_BLUE ) == true then
                              EffectDC():Set_Int(1, 1)
                           end
                           if card:GetColour():Test( COLOUR_BLACK ) == true then
                              EffectDC():Set_Int(2, 1)
                           end
                           if card:GetColour():Test( COLOUR_RED ) == true then
                              EffectDC():Set_Int(3, 1)
                           end
                           if card:GetColour():Test( COLOUR_GREEN ) == true then
                              EffectDC():Set_Int(4, 1)
                           end
                        end
                        totalCMC = totalCMC + card:GetConvertedManaCost()
                        card:GetPlayer():Sacrifice(card)
                     end
                  end
               end
               EffectDC():Set_Int(5, totalCMC)
            end
         end
      </RESOLUTION_TIME_ACTION>
   </COST>
Xander9009 wrote:Last, and most confusingly, I can't figure out why my game keeps crashing. Unlike before, it's a consistent crash, but I can't figure out what's going on. Basically, it was working fine before, but now, if I have a creature on the battlefield and I summon another, then the game crashes. This happened even when I put just two cards alone in a deck (with my test card, which I haven't changed at all). Play one: fine. Play the other: crash immediately. The only thing that stopped the crashes was changing the casting cost to {1}. This isn't restricted to the two cards I used in my test deck, though. Any of my new cards will do it. I've even had it happen with base cards, which tells me it's nothing to do with the cards themselves. More testing revealed the second card I cast doesn't even have to be a creature, anything will prompt it. I'm at a loss at this point. The thing is, I stripped them down to the following:
| Open
Code: Select all
<?xml version='1.0' encoding='UTF-8'?>
<CARD_V2 ExportVersion="1">
   <FILENAME text="SELESNYA_EMISSARY_90090014" />
   <CARDNAME text="SELESNYA_EMISSARY" />
   <TITLE>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Selesnya Emissary]]></LOCALISED_TEXT>
   </TITLE>
   <MULTIVERSEID value="90090014" />
   <ARTID value="90090014" />
   <ARTIST name="James Ryman" />
   <CASTING_COST cost="{W}{G}" />
   <FLAVOURTEXT>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[The Selesnya are famed for their ability to raise an army from nothing.]]></LOCALISED_TEXT>
   </FLAVOURTEXT>
   <TYPE metaname="Creature" />
   <SUB_TYPE metaname="Cleric" />
   <EXPANSION value="RTR" />
   <RARITY metaname="C" />
   <POWER value="2" />
   <TOUGHNESS value="2" />
</CARD_V2>
and the other card was similarly stripped down, but with a different cost. The moment I try playing one while the other is already out, it crashes. Is there some bug I didn't know about? Or is the deck builder (I'm using yours) possibly messing up the deck colors or something? I wouldn't expect so, but I can't think of why this would happen. I thought it might have been a memory issue, but restarting the computer didn't fix it, so it's not something stuck in the memory; and task manager shows the game using less than half a gig of ram and it never drastically changes.
This almost sounds like you are using old versions of the cards or that one of the other cards in your test deck or the opponent's deck is the one causing the problem.

If the problem was with the deck's land pool (deck colours) not containing the correct basic lands then normally it would be crashing going into the match not once a couple of creatures enter the battlefield.
RiiakShiNal
Programmer
 
Posts: 2188
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: Need help fixing a custom card

Postby Xander9009 » 01 May 2014, 02:27

RiiakShiNal wrote:I'm not seeing anything obviously wrong with your code. However, I believe the problem may be in granting the Cipher ability to another card and then trying to access the LinkedDC(). Card A grants Cipher to Card B then Card B gets nailed onto Card C and grants Card C the TRIGGERED_ABILITY so does the LinkedDC refer to the LinkedDC of Card A or Card B, I think this is where the engine gets confused. In that case you may need to use an ObjectDC to get around the issue.
Okay, I've attempted to use an ObjectDC, but since I've never used your functions before, I don't know what I'm doing wrong with them. Here's the code from the first granted ability. This ability should grant the second, but the duration returns a nil card pointer (I get 1 life), so it exits:
| Open
Code: Select all
   <SPELL_ABILITY resource_id="0">
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Cipher]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[Cryptage]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Cifrar.]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Chiffrieren]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Cifrare]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[暗号]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[암호문]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Шифр]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Cifrar]]></LOCALISED_TEXT>
      <RESOLUTION_TIME_ACTION>
         local filter = ClearFilter()
         filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
         filter:Add(FE_CONTROLLER, OP_IS, EffectController() )
         if EffectSource():IsToken() == false then
            EffectController():ChooseItem( "CARD_QUERY_CHOOSE_A_CARD_TO_ENCODE_ONTO", EffectDC():Make_Targets(1), QUERY_FLAG_MAY )
         end
      </RESOLUTION_TIME_ACTION>
      <RESOLUTION_TIME_ACTION>
         local cipherDC = EffectDC():Get_Targets(1)
         if cipherDC ~= nil then
            local chosenCard = cipherDC:Get_CardPtr(0)
            if chosenCard ~= nil then
               local effectSource = EffectSource()
               if (effectSource ~= nil) then
                  effectSource:Exile()
                  effectSource:NailOnto(chosenCard)
                  local DC = RSN_GetObjectDC( chosenCard, true )
                  if DC ~= nil then
                     DC:Set_CardPtr(0, effectSource)
                  end
               end
            end
         end
      </RESOLUTION_TIME_ACTION>
      <CONTINUOUS_ACTION layer="6">
         local DC = RSN_GetObjectDC( chosenCard, true )
         if DC ~= nil then
            local chosencard = DC:Get_CardPtr(0)
            if chosencard ~= nil then
               local characteristics = chosencard:GetCurrentCharacteristics()
               characteristics:GrantAbility(1)
               chosencard:AddScore(150)
            end
         end
      </CONTINUOUS_ACTION>
      <DURATION>
         local DC = RSN_GetObjectDC( chosenCard )
         if DC ~= nil then
            EffectController():GainLife(1)
            if DC:Get_CardPtr(0) ~= nil then
               EffectController():GainLife(1)
               local chosenCardDC = EffectDC():Get_Targets(1)
               if chosenCardDC ~= nil and chosenCardDC:Get_CardPtr(0) ~= nil then
                  return false
               end
            end
         end
         return true
      </DURATION>
   </SPELL_ABILITY>
I inserted this
Code: Select all
if DC:Get_CardPtr(0) ~= nil then
   EffectController():GainLife(1)
end
and I got the life there, but in the duration, this same function returns nil. Also, I assume I should change the card pointer 0 to some other number once it's working?

RiiakShiNal wrote:Count() should not remove the targets, but you could always try putting the target chest into a variable to access it later.
When I use that code (which is how I had it set up originally, but I pasted it in and re-tested, just to be sure), I get 4 life. So now, 'targets' isn't nil, but 'card' is. I decided to try replacing the 'i' variable when getting the pointer and now it's working. I just made a card variable for each of the 5 possible sacrificed cards before counting them. I don't know why it's working if it wouldn't the other way, but it is.
| Open
Code: Select all
<RESOLUTION_TIME_ACTION>
   if EffectDC():Get_Targets(0) ~= nil then
      local targets = EffectDC():Get_Targets(0)
      local card0 = targets:Get_CardPtr(0)
      local card1 = targets:Get_CardPtr(1)
      local card2 = targets:Get_CardPtr(2)
      local card3 = targets:Get_CardPtr(3)
      local card4 = targets:Get_CardPtr(4)
      local count = targets:Count()
      if count &gt; 0 then
         EffectDC():Set_Int(0, 0)
         EffectDC():Set_Int(1, 0)
         EffectDC():Set_Int(2, 0)
         EffectDC():Set_Int(3, 0)
         EffectDC():Set_Int(4, 0)
         local totalCMC = 0
         for i=0,count-1 do
            local card
            if i == 0 then
               card = card0
            elseif i == 1 then
               card = card1
            elseif i == 2 then
               card = card2
            elseif i == 3 then
               card = card3
            elseif i == 4 then
               card = card4
            end
            if card ~= nil then
               if card:GetColour():GetNumColours() &gt; 0 then
                  if card:GetColour():Test( COLOUR_WHITE ) == true then
                     EffectDC():Set_Int(0, 1)
                  end
                  if card:GetColour():Test( COLOUR_BLUE ) == true then
                     EffectDC():Set_Int(1, 1)
                  end
                  if card:GetColour():Test( COLOUR_BLACK ) == true then
                     EffectDC():Set_Int(2, 1)
                  end
                  if card:GetColour():Test( COLOUR_RED ) == true then
                     EffectDC():Set_Int(3, 1)
                  end
                  if card:GetColour():Test( COLOUR_GREEN ) == true then
                     EffectDC():Set_Int(4, 1)
                  end
               end
               totalCMC = totalCMC + card:GetConvertedManaCost()
               card:GetPlayer():Sacrifice(card)
            end
         end
         EffectDC():Set_Int(5, totalCMC)
      end
   end
</RESOLUTION_TIME_ACTION>
RiiakShiNal wrote:This almost sounds like you are using old versions of the cards or that one of the other cards in your test deck or the opponent's deck is the one causing the problem.

If the problem was with the deck's land pool (deck colours) not containing the correct basic lands then normally it would be crashing going into the match not once a couple of creatures enter the battlefield.
Regarding the lands, that's what I thought, but I didn't know if it might react differently in different scenarios for some reason. I'll keep testing. I'll make it a point to remake a few of the cards entirely and test that.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby RiiakShiNal » 01 May 2014, 11:26

Xander9009 wrote:Okay, I've attempted to use an ObjectDC, but since I've never used your functions before, I don't know what I'm doing wrong with them. Here's the code from the first granted ability. This ability should grant the second, but the duration returns a nil card pointer (I get 1 life), so it exits:
| Open
Code: Select all
   <SPELL_ABILITY resource_id="0">
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Cipher]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[Cryptage]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Cifrar.]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Chiffrieren]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Cifrare]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[暗号]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[암호문]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Шифр]]></LOCALISED_TEXT>
      <LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Cifrar]]></LOCALISED_TEXT>
      <RESOLUTION_TIME_ACTION>
         local filter = ClearFilter()
         filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
         filter:Add(FE_CONTROLLER, OP_IS, EffectController() )
         if EffectSource():IsToken() == false then
            EffectController():ChooseItem( "CARD_QUERY_CHOOSE_A_CARD_TO_ENCODE_ONTO", EffectDC():Make_Targets(1), QUERY_FLAG_MAY )
         end
      </RESOLUTION_TIME_ACTION>
      <RESOLUTION_TIME_ACTION>
         local cipherDC = EffectDC():Get_Targets(1)
         if cipherDC ~= nil then
            local chosenCard = cipherDC:Get_CardPtr(0)
            if chosenCard ~= nil then
               local effectSource = EffectSource()
               if (effectSource ~= nil) then
                  effectSource:Exile()
                  effectSource:NailOnto(chosenCard)
                  local DC = RSN_GetObjectDC( chosenCard, true )
                  if DC ~= nil then
                     DC:Set_CardPtr(0, effectSource)
                  end
               end
            end
         end
      </RESOLUTION_TIME_ACTION>
      <CONTINUOUS_ACTION layer="6">
         local DC = RSN_GetObjectDC( chosenCard, true )
         if DC ~= nil then
            local chosencard = DC:Get_CardPtr(0)
            if chosencard ~= nil then
               local characteristics = chosencard:GetCurrentCharacteristics()
               characteristics:GrantAbility(1)
               chosencard:AddScore(150)
            end
         end
      </CONTINUOUS_ACTION>
      <DURATION>
         local DC = RSN_GetObjectDC( chosenCard )
         if DC ~= nil then
            EffectController():GainLife(1)
            if DC:Get_CardPtr(0) ~= nil then
               EffectController():GainLife(1)
               local chosenCardDC = EffectDC():Get_Targets(1)
               if chosenCardDC ~= nil and chosenCardDC:Get_CardPtr(0) ~= nil then
                  return false
               end
            end
         end
         return true
      </DURATION>
   </SPELL_ABILITY>
I inserted this
Code: Select all
if DC:Get_CardPtr(0) ~= nil then
   EffectController():GainLife(1)
end
and I got the life there, but in the duration, this same function returns nil. Also, I assume I should change the card pointer 0 to some other number once it's working?
I would be surprised if your DURATION or CONTINUOUS_ACTION worked at all since you are trying to get the ObjectDC for nil (local variables don't carry over between blocks so chosenCard is nil). Also since you are Exiling the source card you probably need to protect the pointer so that it isn't cleared.
RiiakShiNal
Programmer
 
Posts: 2188
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: Need help fixing a custom card

Postby Xander9009 » 04 May 2014, 20:24

RiiakShiNal wrote:I would be surprised if your DURATION or CONTINUOUS_ACTION worked at all since you are trying to get the ObjectDC for nil (local variables don't carry over between blocks so chosenCard is nil). Also since you are Exiling the source card you probably need to protect the pointer so that it isn't cleared.
Finally got some free time and got that fixed. I'm not sure how I overlooked it. I kind of assumed that the issue was that I was using the ObjectDC functions incorrectly since I've never used them before. I guess I should remember the basics are still important... Thanks, though.

Now all that's left (besides the odd crashing) is the Imprint ability. I managed to get everything working except one thing. In the following code, the first continuous action doesn't fire at all. If I change the layer to 7C, it works (the entire card, not just this section, but the next granted ability and everything). I suspect it's related to the fact that the ability that's granting this static ability is also on layer 6. So, perhaps in a situation where ability A grants ability B which grants ability C, the layer A uses to grant B must be lower than the layer B uses to grant C. This appears to be the case, and the card is working with layer 7C. I'll switch it 7A if it works (I expect it will), but is there a better way to do this?

| Open
Code: Select all
<STATIC_ABILITY resource_id="1">
      <CONTINUOUS_ACTION layer="6">
         if EffectSource() ~= nil then
            local permanentDC = RSN_ObjectDC()
            if permanentDC ~= nil then
               local imprintedCard = permanentDC:Get_CardPtr(900900040)
               if imprintedCard ~= nil and ( imprintedCard:GetCardType():Test( CARD_TYPE_INSTANT ) == true or imprintedCard:GetCardType():Test( CARD_TYPE_SORCERY ) == true ) then
                  EffectSource():GetCurrentCharacteristics():GrantAbility(2)
               end
            end
         end
      </CONTINUOUS_ACTION>
      <CONTINUOUS_ACTION layer="7C">
         if EffectSource() ~= nil then
            local permanentDC = RSN_ObjectDC()
            if permanentDC ~= nil then
               local imprintedCard = permanentDC:Get_CardPtr(900900040)
               if imprintedCard ~= nil and imprintedCard:GetCardType():IsPermanent() == true and EffectSource():GetCardType():Test( CARD_TYPE_CREATURE ) == true then
                  local CMC = imprintedCard:GetConvertedManaCost()
                  if CMC &gt; 0 then
                     EffectSource():GetCurrentCharacteristics():Power_Add( CMC )
                     EffectSource():GetCurrentCharacteristics():Toughness_Add( CMC )
                  end
               end
            end
         end
      </CONTINUOUS_ACTION>
   </STATIC_ABILITY>
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby Xander9009 » 04 May 2014, 22:33

So, I might have solved the crashing problem. It's not 100% confirmed, but I think it might have had to do with recycling deck ids. I was deleting the old file and reusing that id. It was just a test deck, so I didn't want to use a whole crap-ton of ids just for testing. When I made a deck by checking for the first available id (which was only [prefix]-3 because I only have a couple decks in my folder), I was able to play all of the cards with a CMC of 2 or less in the same turn without crashing. I didn't think that would be an issue, and I don't imagine those ids are permanently unusable, but since there's not real reason not to use a new id every time, I'll just stick to that and see if the problem crops back up.

So, they're now 99% working. I just have a couple of minor bugs that need worked out. (For instance, "Exile X cards and return them under their owner's control" was accidentally returning them under my control, which, while pretty nice, was perhaps a little overpowered, especially since it was permanent lol.)

So, thank you for all the help, Riiak, and TFM, too. It took two pages, but they're all in a 99% working state finally. It's greatly appreciated.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby RiiakShiNal » 04 May 2014, 23:04

Xander9009 wrote:So, I might have solved the crashing problem. It's not 100% confirmed, but I think it might have had to do with recycling deck ids. I was deleting the old file and reusing that id. It was just a test deck, so I didn't want to use a whole crap-ton of ids just for testing. When I made a deck by checking for the first available id (which was only [prefix]-3 because I only have a couple decks in my folder), I was able to play all of the cards with a CMC of 2 or less in the same turn without crashing. I didn't think that would be an issue, and I don't imagine those ids are permanently unusable, but since there's not real reason not to use a new id every time, I'll just stick to that and see if the problem crops back up.
IDs are generally not permanently used, if the first available ID is not the ID of a deck that you just removed then there is another deck or something using that same ID. For example if you create a new deck with a new ID, then delete that deck, load the Deck Builder and look for first available ID it will find the first available ID as the ID of the deck you just removed.
RiiakShiNal
Programmer
 
Posts: 2188
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: Need help fixing a custom card

Postby Xander9009 » 06 May 2014, 22:43

RiiakShiNal wrote:IDs are generally not permanently used, if the first available ID is not the ID of a deck that you just removed then there is another deck or something using that same ID. For example if you create a new deck with a new ID, then delete that deck, load the Deck Builder and look for first available ID it will find the first available ID as the ID of the deck you just removed.
That was originally how I thought it worked (since that was the logical way for it to work) and that's why I was doing it like that. The issue might also be related to to much being processed at once. I'm still not sure, but as long as I play the deck normally instead of cheating with my test card, it seems to not crash, so I'm not overly worried about it.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
User avatar
Xander9009
Programmer
 
Posts: 2905
Joined: 29 Jun 2013, 07:44
Location: Indiana, United States
Has thanked: 121 times
Been thanked: 445 times

Re: Need help fixing a custom card

Postby MC Brodie » 06 May 2014, 23:18

I haven't read through this whole thread (you and Riiak write books :) ) but I've experienced similar crashes when using thefiremind's Leyline of Deity to cast cards with a hybrid casting cost (like Dovescape or Kitchen Finks). At least that was what I narrowed it down to. When I would use the "cast for free" ability from Leyline of Deity and cast a hybrid costing card, the card would freeze on the stack. I can't remember if the game crashed after that or if I just had to restart.

Like I said, I haven't read the whole thread so I don't know if this is the issue but I figured I'd throw it out there.
-----------------------------------------------------------------------
Song of the Day: 46 and 2 (cover)
MC Brodie
 
Posts: 310
Joined: 01 Jun 2013, 00:10
Has thanked: 44 times
Been thanked: 34 times

PreviousNext

Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 16 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 16 users online :: 0 registered, 0 hidden and 16 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 16 guests

Login Form