Page 1 of 1

LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 09 Oct 2016, 03:33
by Rholin
I want to create a new type of ability called "overspell" which consists in 2 effects:
1. If this card is in your hand, whenever you cast a sorcery or instant, it gains a overspell point.
2. when you cast this spell, it will have extra effect according to it's overspell point number.

For example, I made a card "Insight":
Code: Select all
   <SPELL_ABILITY linked_ability_group="0">
      <LOCALISED_TEXT LanguageCode="en-US">Draw a card.</LOCALISED_TEXT>
      <RESOLUTION_TIME_ACTION>
         if EffectSource() ~= nil then
            local n = LinkedDC():Get_Int("overspell")
            EffectController():DrawCards(1+n)
            LinkedDC():Set_Int("overspell",0)
         end
      </RESOLUTION_TIME_ACTION>
   </SPELL_ABILITY>
   <TRIGGERED_ABILITY active_zone="ZONE_ANY" replacement_effect="1" linked_ability_group="0">
      <LOCALISED_TEXT LanguageCode="en-US">Overspell:</LOCALISED_TEXT>
      <TRIGGER value="SPELL_PLAYED" simple_qualifier="controller">
         return (TriggerObject():GetCardType():Test(CARD_TYPE_SORCERY) or TriggerObject():GetCardType():Test(CARD_TYPE_INSTANT)) and (TriggerObject() ~= EffectSource())
      </TRIGGER>
      <RESOLUTION_TIME_ACTION>
         if EffectSource() ~= nil then
            if LinkedDC():Get_Int("overspell") == nil then
               LinkedDC():Set_Int("overspell",0)
            end
            local ovsp = LinkedDC():Get_Int("overspell")
            LinkedDC():Set_Int("overspell", ovsp+1)
         end
      </RESOLUTION_TIME_ACTION>
      <DERIVED_INFO tag="DERIVED_INFO_X_OVSP_ON_THIS_CARD">
         return LinkedDC():Get_Int("overspell")
      </DERIVED_INFO>
   </TRIGGERED_ABILITY>
   <QUERYTEXT tag="DERIVED_INFO_X_OVSP_ON_THIS_CARD">
      <LOCALISED_TEXT LanguageCode="en-US">draw %d card(s) more</LOCALISED_TEXT>
   </QUERYTEXT>
In the game, the overspell trigger works but when the card is in the stack zone, the LinkedDC():Get_Int("overspell") is always 0.

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 09 Oct 2016, 04:05
by Xander9009
First up, on lines 21 and 22, you can just use LinkedDC():Add_Int("overspell", 1).

The issue is probably that on line 5, you're getting the int stored in DuelDataChest instead of LinkedDC().

If that doesn't work, then here, try this code.
Code: Select all
   <SPELL_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US">Draw a card.</LOCALISED_TEXT>
      <RESOLUTION_TIME_ACTION>
         local oController = EffectController()
         local oSource = EffectSource()
         if oController ~= nil and oSource ~= nil then
            local oPlayerDC = oController:PlayerDataChest()
            if oPlayerDC ~= nil then
               local oOverspellDC = oPlayerDC:Get_Chest("Overspell_Chest_Register")
               if oOverspellDC ~= nil then
                  local oSpells = oOverspellDC:Get_Chest(1)
                  local oCounts = oOverspellDC:Get_Chest(2)
                  for i=0;oOverspellDC:Get_Int(0) do
                     if oSpells:Get_CardPtr(i) == oSource then
                        EffectController():DrawCards(Counts:Get_Int(i)+1)
                        Counts:Set_Int(0)
                     end
                  end
               end
            end
         end
         return 0
      </RESOLUTION_TIME_ACTION>
   </SPELL_ABILITY>
   <TRIGGERED_ABILITY active_zone="ZONE_ANY" replacement_effect="1">
      <LOCALISED_TEXT LanguageCode="en-US">Overspell:</LOCALISED_TEXT>
      <TRIGGER value="SPELL_PLAYED" simple_qualifier="objectyoucontrol">
         return TriggerObject() ~= nil and (TriggerObject():GetCardType():Test(CARD_TYPE_INSTANT) or TriggerObject():GetCardType():Test(CARD_TYPE_SORCERY))
      </TRIGGER>
      <RESOLUTION_TIME_ACTION>
         local oController = EffectController()
         local oSource = EffectSource()
         if oController ~= nil and oSource ~= nil then
            local oPlayerDC = oController:PlayerDataChest()
            if oPlayerDC ~= nil then
               local oOverspellDC = oPlayerDC:Get_Chest("Overspell_Chest_Register")
               if oOverspellDC == nil then
                  oOverspellDC = oPlayerDC:Make_Chest("Overspell_Chest_Register")
                  if oOverspellDC ~= nil then
                     oOverspellDC:Make_Chest(1)
                     oOverspellDC:Make_Chest(2)
                  end
               end
               if oOverspellDC ~= nil then
                  local oSpells = oOverspellDC:Get_Chest(1)
                  local oCounts = oOverspellDC:Get_Chest(2)
                  for i=0;oOverspellDC:Get_Int(0) do
                     if oSpells:Get_CardPtr(i) == oSource then
                        oCounts:Int_Add(i, 1)
                        break
                     end
                  end
               end
            end
         end
      </RESOLUTION_TIME_ACTION>
      <DERIVED_INFO tag="DERIVED_INFO_X_OVSP_ON_THIS_CARD">
         local oController = EffectController()
         local oSource = EffectSource()
         if oController ~= nil and oSource ~= nil then
            local oPlayerDC = oController:PlayerDataChest()
            if oPlayerDC ~= nil then
               local oOverspellDC = oPlayerDC:Get_Chest("Overspell_Chest_Register")
               if oOverspellDC ~= nil then
                  local oSpells = oOverspellDC:Get_Chest(1)
                  local oCounts = oOverspellDC:Get_Chest(2)
                  for i=0;oOverspellDC:Get_Int(0) do
                     if oSpells:Get_CardPtr(i) == oSource then
                        return oCounts:Get_Int(i)
                     end
                  end
               end
            end
         end
         return 0
      </DERIVED_INFO>
   </TRIGGERED_ABILITY>
   <QUERYTEXT tag="DERIVED_INFO_X_OVSP_ON_THIS_CARD">
      <LOCALISED_TEXT LanguageCode="en-US">draw %d card(s) more</LOCALISED_TEXT>
   </QUERYTEXT>
Note that I code for 2014, so I can't guarantee any of this (or even test it).

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 09 Oct 2016, 04:22
by Rholin
Xander9009 wrote:First up, on lines 21 and 22, you can just use LinkedDC():Add_Int("overspell", 1).

The issue is probably that on line 5, you're getting the int stored in DuelDataChest instead of LinkedDC().

If that doesn't work, then here, try this code.
Code: Select all
   <SPELL_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US">Draw a card.</LOCALISED_TEXT>
      <RESOLUTION_TIME_ACTION>
         local oController = EffectController()
         local oSource = EffectSource()
         if oController ~= nil and oSource ~= nil then
            local oPlayerDC = oController:PlayerDataChest()
            if oPlayerDC ~= nil then
               local oOverspellDC = oPlayerDC:Get_Chest("Overspell_Chest_Register")
               if oOverspellDC == nil then
                  oOverspellDC = oPlayerDC:Make_Chest("Overspell_Chest_Register")
                  if oOverspellDC ~= nil then
                     oOverspellDC:Make_Chest(1)
                     oOverspellDC:Make_Chest(2)
                  end
               end
               if oOverspellDC ~= nil then
                  local oSpells = oOverspellDC:Get_Chest(1)
                  local oCounts = oOverspellDC:Get_Chest(2)
                  for i=0;oOverspellDC:Get_Int(0) do
                     if oSpells:Get_CardPtr(i) == oSource then
                        EffectController():DrawCards(Counts:Get_Int(i)+1)
                        Counts:Set_Int(0)
                     end
                  end
               end
            end
         end
         return 0
      </RESOLUTION_TIME_ACTION>
   </SPELL_ABILITY>
   <TRIGGERED_ABILITY active_zone="ZONE_ANY" replacement_effect="1">
      <LOCALISED_TEXT LanguageCode="en-US">Overspell:</LOCALISED_TEXT>
      <TRIGGER value="SPELL_PLAYED" simple_qualifier="objectyoucontrol">
         return TriggerObject() ~= nil and (TriggerObject():GetCardType():Test(CARD_TYPE_INSTANT) or TriggerObject():GetCardType():Test(CARD_TYPE_SORCERY))
      </TRIGGER>
      <RESOLUTION_TIME_ACTION>
         local oController = EffectController()
         local oSource = EffectSource()
         if oController ~= nil and oSource ~= nil then
            local oPlayerDC = oController:PlayerDataChest()
            if oPlayerDC ~= nil then
               local oOverspellDC = oPlayerDC:Get_Chest("Overspell_Chest_Register")
               if oOverspellDC == nil then
                  oOverspellDC = oPlayerDC:Make_Chest("Overspell_Chest_Register")
                  if oOverspellDC ~= nil then
                     oOverspellDC:Make_Chest(1)
                     oOverspellDC:Make_Chest(2)
                  end
               end
               if oOverspellDC ~= nil then
                  local oSpells = oOverspellDC:Get_Chest(1)
                  local oCounts = oOverspellDC:Get_Chest(2)
                  for i=0;oOverspellDC:Get_Int(0) do
                     if oSpells:Get_CardPtr(i) == oSource then
                        oCounts:Int_Add(i, 1)
                        break
                     end
                  end
               end
            end
         end
      </RESOLUTION_TIME_ACTION>
      <DERIVED_INFO tag="DERIVED_INFO_X_OVSP_ON_THIS_CARD">
         local oController = EffectController()
         local oSource = EffectSource()
         if oController ~= nil and oSource ~= nil then
            local oPlayerDC = oController:PlayerDataChest()
            if oPlayerDC ~= nil then
               local oOverspellDC = oPlayerDC:Get_Chest("Overspell_Chest_Register")
               if oOverspellDC == nil then
                  oOverspellDC = oPlayerDC:Make_Chest("Overspell_Chest_Register")
                  if oOverspellDC ~= nil then
                     oOverspellDC:Make_Chest(1)
                     oOverspellDC:Make_Chest(2)
                  end
               end
               if oOverspellDC ~= nil then
                  local oSpells = oOverspellDC:Get_Chest(1)
                  local oCounts = oOverspellDC:Get_Chest(2)
                  for i=0;oOverspellDC:Get_Int(0) do
                     if oSpells:Get_CardPtr(i) == oSource then
                        return oCounts:Get_Int(i)
                     end
                  end
               end
            end
         end
         return 0
      </DERIVED_INFO>
   </TRIGGERED_ABILITY>
   <QUERYTEXT tag="DERIVED_INFO_X_OVSP_ON_THIS_CARD">
      <LOCALISED_TEXT LanguageCode="en-US">draw %d card(s) more</LOCALISED_TEXT>
   </QUERYTEXT>
Note that I code for 2014, so I can't guarantee any of this (or even test it).
I saw that the LinkedDC didn't work so I tried another ways like DuelDataChest, and forgot to change it back when post the code. Therefore I can confirm that LinkedDC() doesn't work. I'll try your code later, thanks very much!

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 09 Oct 2016, 07:58
by thefiremind
There are some zone changes that wipe LinkedDC. The transition to the stack, if I remember correctly, is a zone change that wipes LinkedDC, so you can't rely on it remembering what you stored there when you cast the spell. The only solution I can think of now is to make a delayed trigger that will set your variable to the right number again after the spell reached the stack.

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 10 Oct 2016, 10:41
by RiiakShiNal
Or use my ObjectDC functions and protect the chest on certain zone changes so that it doesn't clear (you only need to protect it for the zone changes in which you don't want it to clear, such as transitioning to the stack).

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 10 Oct 2016, 10:42
by Xander9009
RiiakShiNal wrote:Or use my ObjectDC functions and protect the chest on certain zone changes so that it doesn't clear (you only need to protect it for the zone changes in which you don't want it to clear, such as transitioning to the stack).
Have those been tested for Magic Duels? I know a few functions (like Int_Inc) have been removed. Your functions were actually my first thought for how to solve it, but I didn't know if they'd been tested with it yet.

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 10 Oct 2016, 11:34
by Rholin
Thanks for help. Today I found a strange thing, it seems that the data are not wiped in the transition, but are more likely temporarily "unaccessible" in the stack zone, because I saw that when the card was in my hand, the derived info was "draw 2 card(s) more", in the stack zone, "draw 0...", but after the resolution, when it was in graveyard, it showed "draw 2 .." again!

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 10 Oct 2016, 12:01
by RiiakShiNal
Xander9009 wrote:Have those been tested for Magic Duels? I know a few functions (like Int_Inc) have been removed. Your functions were actually my first thought for how to solve it, but I didn't know if they'd been tested with it yet.
Oops, I missed that this was for Duels. No, I haven't done any testing with Duels (suffering from lack of time), though if things still work pretty much the same then they should work.

Re: LinkedDC cannot pass data from a trigger to a spell?

PostPosted: 17 Oct 2016, 08:41
by thefiremind
Just a heads up on this matter, if Rholin hasn't found a solution yet: I implemented my own ObjectDC for Magic Duels (which is very simplified thanks to the possibility of using strings as index: I'm using tostring(object) as an index for object). You can find it in my test contents, inside the LOL file for general functions.