Board index Programs with AI or Rules Enforcement Magic: The Gathering - Duels of the Planeswalkers Programming Talk
General DotP 2014 Coding Questions
Moderator: CCGHQ Admins
Re: General DotP 2014 Coding Questions
by GrovyleXShinyCelebi » 13 Dec 2013, 01:07
Aww...RiiakShiNal wrote:No, my ObjectDC functions won't help there as they are locked to the object's instance and each copy would have it's own instance. I can't really think of a good way to get a card and only its copies to access a single chest without having it being influenced by other spells or instances. For example you can't just have a card use a single DuelDataChest() because then if two different copies are cast with one being overloaded and the other without if they access the same chest they would both either be overloaded or not even though different costs were paid.GrovyleXShinyCelebi wrote:Ugh, just tested Overload and you're right as copies aren't being taken account. I wonder if that's something your ObjectDC can solve ('bout time I started using it anyways).
Anyways, is there a trigger or anything to activate Grafted Exoskeleton's second ability? Because I can't seem to find one (there's a trigger that seems to fire when an equipment/aura is unattached from a CREATURE, but not a PERMANENT), and my attempt at an approximation isn't doing much good, either:
- Code: Select all
<TRIGGERED_ABILITY replacement_effect="1">
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Whenever Grafted Exoskeleton becomes unattached from a permanent, sacrifice that permanent.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[À chaque fois que l’Exosquelette greffé devient détaché d’un permanent, sacrifiez ce permanent.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Siempre que el Exoesqueleto injertado sea desanexado de un permanente, sacrifica ese permanente.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Immer wenn das Aufgepfropfte Exoskelett von einer bleibenden Karte gelöst wird, opfere diese bleibende Karte.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Ogniqualvolta l’Esoscheletro Innestato viene tolto da un permanente, sacrifica quel permanente.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[生体融合外骨格がいずれかのパーマネントからはずれるたび、そのパーマネントを生け贄に捧げる。]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[Whenever Grafted Exoskeleton becomes unattached from a permanent, sacrifice that permanent.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Каждый раз когда Пересаженный Экзоскелет открепляется от перманента, пожертвуйте тот перманент.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Toda vez que Exosqueleto Enxertado for solto de uma permanente, sacrifique aquela permanente.]]></LOCALISED_TEXT>
<TRIGGER value="EQUIPMENT_ATTACHED" simple_qualifier="self" />
<RESOLUTION_TIME_ACTION>
local chest = EffectDC():Make_Chest(1)
chest:Set_CardPtr(2, EffectSource():GetParent() )
MTG():CreateDelayedTrigger(0, chest)
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
EffectDC():Set_Int(0, 1)
EffectDC():Set_CardPtr(1, EffectSource():GetParent() )
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
<TRIGGERED_ABILITY resource_id="0">
<TRIGGER value="SPELL_RESOLVED">
if EffectDC():Get_Int(0) == 1 and (EffectSource():GetParent() == nil or EffectSource():GetParent() ~= EffectDC():Get_CardPtr(1)) then
EffectDC():Set_Int(0, 0)
return true
end
</TRIGGER>
<TRIGGER value="ABILITY_RESOLVED">
if EffectDC():Get_Int(0) == 1 and (EffectSource():GetParent() == nil or EffectSource():GetParent() ~= EffectDC():Get_CardPtr(1)) then
EffectDC():Set_Int(0, 0)
return true
end
</TRIGGER>
<RESOLUTION_TIME_ACTION>
local card = EffectDC():Get_CardPtr(2)
if card ~= nil then
local player = card:GetPlayer()
player:Sacrifice( card )
end
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
(in Duels 2014)
Duels 2012: viewtopic.php?f=109&t=12152
Duels 2013: viewtopic.php?f=109&t=12481&p=137458#p137458
Duels 2012: viewtopic.php?f=109&t=12152
Duels 2013: viewtopic.php?f=109&t=12481&p=137458#p137458
-
GrovyleXShinyCelebi - Posts: 294
- Joined: 12 Jun 2013, 18:23
- Has thanked: 14 times
- Been thanked: 37 times
Re: General DotP 2014 Coding Questions
by RiiakShiNal » 13 Dec 2013, 02:54
UNATTACHED_FROM_CREATURE might work for permanents as well (it would not be the first time something was named inappropriately). Though in most cases (not all unfortunately) it will only ever be unattached from a creature since only a creature can be equipped. I say not all cases because you could equip a Mishra's Factory with it while it is a creature then at end of turn when the Mishra's Factory ceases to be a creature it will unattach.
Just getting started: Xander9009's DotP 2014 Community Wad
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
- RiiakShiNal
- Programmer
- Posts: 2185
- Joined: 16 May 2011, 21:37
- Has thanked: 75 times
- Been thanked: 497 times
Re: General DotP 2014 Coding Questions
by MC Brodie » 14 Dec 2013, 14:00
What does the priority attribute for triggered abilities do?
-----------------------------------------------------------------------
Song of the Day: 46 and 2 (cover)
Song of the Day: 46 and 2 (cover)
Re: General DotP 2014 Coding Questions
by thefiremind » 14 Dec 2013, 14:04
What do you mean with "attribute"? Some people call "attributes" in an XML file the same things we call "tags", but then which one are you talking about?MC Brodie wrote:What does the attribute for triggered abilities do?
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
Re: General DotP 2014 Coding Questions
by MC Brodie » 14 Dec 2013, 14:10
Sorry I edited it back in there after you quoted it. You are quick . I meant the priority attribute for the triggered_ability tag. Like:
- Code: Select all
<TRIGGERED_ABILITY priority="20">
-----------------------------------------------------------------------
Song of the Day: 46 and 2 (cover)
Song of the Day: 46 and 2 (cover)
Re: General DotP 2014 Coding Questions
by thefiremind » 14 Dec 2013, 15:49
OK, then, let's start with a disclaimer: what I'm about to explain is guaranteed to work for non-internal abilities (no replacement_effect, no replacement_query). Otherwise, I have experienced cases where priority didn't give me the effect I was expecting.MC Brodie wrote:Sorry I edited it back in there after you quoted it. You are quick . I meant the priority attribute for the triggered_ability tag. Like:
- Code: Select all
<TRIGGERED_ABILITY priority="20">
The priority attribute is the DotP developers' answer for the lack of triggered ability ordering on the stack. In real Magic, you always have the rights to order triggered abilities on the stack if they all trigger at the same time and you control them all (for different controllers, both real Magic and DotP follow the APNAP rule, that is "Active Player - Non-Active Player", so the abilities controlled by the player who's playing the current turn go to the stack first).
The priority attribute sets a fixed order for the triggered abilities to resolve when real Magic would allow their controller to decide. Big emphasis on resolve: this means that they'll be put on the stack in the reverse order of priority.
The most obvious example: Deathbringer Liege from DotP2013. When playing a spell you would be really pissed off if the second triggered ability resolved before the first one, wouldn't you? That's why the first triggered ability has been coded with priority="1": it will always resolve before the second (which has the default priority of 0).
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
Re: General DotP 2014 Coding Questions
by GrovyleXShinyCelebi » 14 Dec 2013, 20:28
Hmm... speaking of priorities, what priority is the TARGET_DEFINITION block of a SPELL_ABILITY, compared to a COST block of a UTILITY_ABILITY? Can you manipulate them so that the TARGET_DEFINITION activates after the UTILITY_ABILITY (as in, a bool put in a data chest in a COST block can be read in a TARGET_DEFINITION block, which could potentially allow for a perfect Overload ability)?
(in Duels 2014)
Duels 2012: viewtopic.php?f=109&t=12152
Duels 2013: viewtopic.php?f=109&t=12481&p=137458#p137458
Duels 2012: viewtopic.php?f=109&t=12152
Duels 2013: viewtopic.php?f=109&t=12481&p=137458#p137458
-
GrovyleXShinyCelebi - Posts: 294
- Joined: 12 Jun 2013, 18:23
- Has thanked: 14 times
- Been thanked: 37 times
Re: General DotP 2014 Coding Questions
by thefiremind » 14 Dec 2013, 21:22
I lost track of how many tries I made one day when I wanted to try and code bestow, but all efforts are vain. The steps when you play a spell with alternative costs are:GrovyleXShinyCelebi wrote:Hmm... speaking of priorities, what priority is the TARGET_DEFINITION block of a SPELL_ABILITY, compared to a COST block of a UTILITY_ABILITY? Can you manipulate them so that the TARGET_DEFINITION activates after the UTILITY_ABILITY (as in, a bool put in a data chest in a COST block can be read in a TARGET_DEFINITION block, which could potentially allow for a perfect Overload ability)?
- Choose how to pay.
- Choose targets.
- Pay.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
Re: General DotP 2014 Coding Questions
by MC Brodie » 16 Dec 2013, 03:49
I'm trying to expand on my modding DotP knowledge and start to use user-defined functions. I'm just trying to something simple (ask a multiple choice question based on input parameters) but I have some questions. First, what exactly is an LOL file? As in, if I would like to see some documentation of the appropriate syntax, where should I look? I think I asked this before but I can't find it and unfortunately, I forgot.
Is it possible to define a function with optional input parameters? For example, with a function like this:
I know these are things that I can write my own tests for and figure out. Though for me, I feel like a little explanation helps me understand it better.
Is it possible to define a function with optional input parameters? For example, with a function like this:
- Code: Select all
MyFunction = function ( stringX, stringY, stringZ )
end
I know these are things that I can write my own tests for and figure out. Though for me, I feel like a little explanation helps me understand it better.
-----------------------------------------------------------------------
Song of the Day: 46 and 2 (cover)
Song of the Day: 46 and 2 (cover)
Re: General DotP 2014 Coding Questions
by thefiremind » 16 Dec 2013, 09:27
It's a file that contains Lua code. Simple as that. The LOL extension (opposed to LUA extension) should indicate a compiled code, and in fact official LOL files are compiled (you can't open them with Notepad and understand what's in them, you need a Lua decompiler and even with that, some of them can't be properly decompiled), but since the LUA extension is ignored by DotP since DotP2012, we give LOL extension to our files as well even if they are not compiled.MC Brodie wrote:First, what exactly is an LOL file?
http://www.lua.org/manual/MC Brodie wrote:As in, if I would like to see some documentation of the appropriate syntax, where should I look?
I'm not totally sure, but I think this is a Lua feature: when you don't specify a parameter, then it's nil.MC Brodie wrote:Is it possible to define a function with optional input parameters? For example, with a function like this:I'd like to call it with only "MyFunction("X","Y")". I've been looking at some of the LOL files from published mods and it looks like this is ok and is possible without "function overloading" but they are still hard for me to follow. If I call MyFunction("X","Y") will stringZ be equal to nil?
- Code: Select all
MyFunction = function ( stringX, stringY, stringZ )
end
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
Re: General DotP 2014 Coding Questions
by MC Brodie » 16 Dec 2013, 12:42
Thank you for the explanation. The answer to my function question is in Section 3.4.10 in the link below. It looks like you can call an under-defined or over-defined function. Parameters that are not defined when called are nil. I guess nothing happens with the extra parameters provided when a function is called but it doesn't cause problems. I also learned about a vararg expression and "syntactic sugar" . Interesting stuff, thanks!
http://www.lua.org/manual/5.2/manual.html#3.1
http://www.lua.org/manual/5.2/manual.html#3.1
-----------------------------------------------------------------------
Song of the Day: 46 and 2 (cover)
Song of the Day: 46 and 2 (cover)
Re: General DotP 2014 Coding Questions
by thefiremind » 16 Dec 2013, 13:28
I always found this term quite funny. Nobody clearly explained to me what it means, but judging from the context, it's something that a programming language would want written in some way, but you are allowed to write it also in another way because it's easier to read for the human eye and/or people could be more familiar with that way from other programming languages.MC Brodie wrote:"syntactic sugar"
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
Re: General DotP 2014 Coding Questions
by RiiakShiNal » 16 Dec 2013, 14:53
That is pretty much exactly what it means. Here is a wiki page on it. Though I always associate it with "Sugar-coating the language."thefiremind wrote:I always found this term quite funny. Nobody clearly explained to me what it means, but judging from the context, it's something that a programming language would want written in some way, but you are allowed to write it also in another way because it's easier to read for the human eye and/or people could be more familiar with that way from other programming languages.MC Brodie wrote:"syntactic sugar"
Often I like to make use of syntactic sugar, though there are times when I avoid it for the purpose of clarity as sometimes syntactic sugar can make things confusing (for example omitting parenthesis in complex calculations can be confusing if you are not completely familiar the order of operations in a particular language).
Just getting started: Xander9009's DotP 2014 Community Wad
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
- RiiakShiNal
- Programmer
- Posts: 2185
- Joined: 16 May 2011, 21:37
- Has thanked: 75 times
- Been thanked: 497 times
Re: General DotP 2014 Coding Questions
by GrovyleXShinyCelebi » 18 Jan 2014, 03:45
Question:
I'm trying to make a suspend 4 ability borrowing TFM's suspend functions:
[lua] [string "TESTCARD2_TITLE (AVAILABILITY)~0x00000164"]:2: attempt to call global 'TFM_SuspendCheck' (a nil value)
Does anyone know what might be the issue?
Thanks!
I'm trying to make a suspend 4 ability borrowing TFM's suspend functions:
- Code: Select all
<ACTIVATED_ABILITY forced_skip="1" active_zone="ZONE_HAND">
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Suspend 4—{W}{U}]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[Suspension 4 — {W}{U}]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Suspender 4—{W}{U}.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Aussetzen 4 {W}{U}]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Sospendere 4-{W}{U}]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[待機 4―{W}{U}]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[Suspend 4—{W}{U}]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Отсрочка 4—{W}{U}]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Suspender 4—{W}{U}]]></LOCALISED_TEXT>
<COUNTER_REGISTRATION name="Time" proliferate="11" />
<AVAILABILITY>
return TFM_CanBeSuspended()
</AVAILABILITY>
<PLAY_TIME_ACTION>
EffectDC():Protect_CardPtr(COMPARTMENT_ID_EFFECT_SOURCE)
</PLAY_TIME_ACTION>
<COST type="ExileSelf" />
<COST mana_cost="{W}{U}" type="Mana" />
<RESOLUTION_TIME_ACTION>
if EffectSource() ~= nil then
EffectSource():AddCounters( MTG():GetCountersType("Time"), 4 )
end
</RESOLUTION_TIME_ACTION>
<CONTINUOUS_ACTION layer="8">
if EffectSource() ~= nil then
EffectSource():GetCurrentCharacteristics():Bool_Set(TFM_FAKE_SUSPEND_CHARACTERISTIC, 1)
end
</CONTINUOUS_ACTION>
<CONTINUOUS_ACTION layer="6">
if EffectSource() ~= nil then
local characteristics = EffectSource():GetCurrentCharacteristics()
characteristics:GrantAbility(0)
characteristics:GrantAbility(1)
--characteristics:GrantAbility(2)
end
</CONTINUOUS_ACTION>
<DURATION>
return EffectSource() == nil
</DURATION>
<AI_AVAILABILITY window_step="main_2" window_turn="my_turn" type="window" />
</ACTIVATED_ABILITY>
<TRIGGERED_ABILITY resource_id="0" active_zone="ZONE_EXILE">
<TRIGGER value="BEGINNING_OF_PLAYERS_STEP" simple_qualifier="controller">
return MTG():GetStep() == STEP_UPKEEP
</TRIGGER>
<INTERVENING_IF>
return EffectSourceLKI():CountCounters( MTG():GetCountersType("Time") ) > 0
</INTERVENING_IF>
<RESOLUTION_TIME_ACTION>
if EffectSource() ~= nil then
EffectSource():RemoveCounters( MTG():GetCountersType("Time"), 1 )
end
</RESOLUTION_TIME_ACTION>
<AUTO_SKIP always="1" />
</TRIGGERED_ABILITY>
<TRIGGERED_ABILITY resource_id="1" active_zone="ZONE_EXILE">
<TRIGGER value="COUNTERS_CHANGED" simple_qualifier="self">
return GetAmount() < 0 and
CounterTypeIndex() == MTG():GetCountersType("Time") and
EffectSource():CountCounters( MTG():GetCountersType("Time") ) == 0
</TRIGGER>
<RESOLUTION_TIME_ACTION>
local source = EffectSource()
if source ~= nil and source:GetOwner():CanCastSpellForFree(source) then
EffectDC():Protect_CardPtr(COMPARTMENT_ID_EFFECT_SOURCE)
source:GetOwner():CastSpellForFree(source)
end
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local source = EffectSource()
if source ~= nil then
local delayDC = EffectDC():Make_Chest(1)
delayDC:Set_CardPtr(0, source)
delayDC:Protect_CardPtr(0)
delayDC:Set_PlayerPtr( 1, source:GetOwner() )
--MTG():CreateDelayedTrigger(2, delayDC)
end
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
<HELP title="MORE_INFO_TITLE_SUSPEND" body="MORE_INFO_BODY_SUSPEND" zone="ZONE_ANY" />
<AI_CUSTOM_SCORE zone="ZONE_HAND">
if Object():GetOwner():Hand_Count() < 4 then
TFM_AddSuspendScore("{W}{U}")
end
</AI_CUSTOM_SCORE>
[lua] [string "TESTCARD2_TITLE (AVAILABILITY)~0x00000164"]:2: attempt to call global 'TFM_SuspendCheck' (a nil value)
Does anyone know what might be the issue?
Thanks!
(in Duels 2014)
Duels 2012: viewtopic.php?f=109&t=12152
Duels 2013: viewtopic.php?f=109&t=12481&p=137458#p137458
Duels 2012: viewtopic.php?f=109&t=12152
Duels 2013: viewtopic.php?f=109&t=12481&p=137458#p137458
-
GrovyleXShinyCelebi - Posts: 294
- Joined: 12 Jun 2013, 18:23
- Has thanked: 14 times
- Been thanked: 37 times
Re: General DotP 2014 Coding Questions
by thefiremind » 18 Jan 2014, 10:32
There must be something strange going on, because in the code you posted you are using TFM_CanBeSuspended in the AVAILABILITY block, and not TFM_SuspendCheck (which might be how I called the function in the first version, I can't remember). So how can you get an error for a function you didn't use? Maybe you have an old version of your test card that you forgot about?GrovyleXShinyCelebi wrote:[lua] [string "TESTCARD2_TITLE (AVAILABILITY)~0x00000164"]:2: attempt to call global 'TFM_SuspendCheck' (a nil value)
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
Who is online
Users browsing this forum: No registered users and 44 guests