It is currently 26 Apr 2024, 04:40
   
Text Size

General DotP 2014 Coding Questions

Moderator: CCGHQ Admins

Re: General DotP 2014 Coding Questions

Postby GrovyleXShinyCelebi » 13 Dec 2013, 01:07

RiiakShiNal wrote:
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).
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.
Aww... :(

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>
User avatar
GrovyleXShinyCelebi
 
Posts: 294
Joined: 12 Jun 2013, 18:23
Has thanked: 14 times
Been thanked: 37 times

Re: General DotP 2014 Coding Questions

Postby 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.
RiiakShiNal
Programmer
 
Posts: 2185
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: General DotP 2014 Coding Questions

Postby MC Brodie » 14 Dec 2013, 14:00

What does the priority attribute for triggered abilities do?
-----------------------------------------------------------------------
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

Re: General DotP 2014 Coding Questions

Postby thefiremind » 14 Dec 2013, 14:04

MC Brodie wrote:What does the attribute for triggered abilities do?
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?
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times

Re: General DotP 2014 Coding Questions

Postby 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)
MC Brodie
 
Posts: 310
Joined: 01 Jun 2013, 00:10
Has thanked: 44 times
Been thanked: 34 times

Re: General DotP 2014 Coding Questions

Postby thefiremind » 14 Dec 2013, 15:49

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">
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.
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 {WB} 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...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times

Re: General DotP 2014 Coding Questions

Postby 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)?
User avatar
GrovyleXShinyCelebi
 
Posts: 294
Joined: 12 Jun 2013, 18:23
Has thanked: 14 times
Been thanked: 37 times

Re: General DotP 2014 Coding Questions

Postby thefiremind » 14 Dec 2013, 21:22

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)?
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:
  1. Choose how to pay.
  2. Choose targets.
  3. Pay.
When you add an alternative cost, the choice is properly presented before targets are chosen, but any code you add inside the COST block is executed on step 3.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times

Re: General DotP 2014 Coding Questions

Postby 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:
Code: Select all
MyFunction = function ( stringX, stringY, stringZ )
end
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?

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)
MC Brodie
 
Posts: 310
Joined: 01 Jun 2013, 00:10
Has thanked: 44 times
Been thanked: 34 times

Re: General DotP 2014 Coding Questions

Postby thefiremind » 16 Dec 2013, 09:27

MC Brodie wrote:First, what exactly is an LOL file?
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:As in, if I would like to see some documentation of the appropriate syntax, where should I look?
http://www.lua.org/manual/ :P

MC Brodie wrote: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'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?
I'm not totally sure, but I think this is a Lua feature: when you don't specify a parameter, then it's nil.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times

Re: General DotP 2014 Coding Questions

Postby 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
-----------------------------------------------------------------------
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

Re: General DotP 2014 Coding Questions

Postby thefiremind » 16 Dec 2013, 13:28

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

Re: General DotP 2014 Coding Questions

Postby RiiakShiNal » 16 Dec 2013, 14:53

thefiremind wrote:
MC Brodie wrote:"syntactic sugar"
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.
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."

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).
RiiakShiNal
Programmer
 
Posts: 2185
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 497 times

Re: General DotP 2014 Coding Questions

Postby GrovyleXShinyCelebi » 18 Jan 2014, 03:45

Question:

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") ) &gt; 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() &lt; 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() &lt; 4 then
     TFM_AddSuspendScore("{W}{U}")
  end
  </AI_CUSTOM_SCORE>
I made sure that his D14_TFM_GENERAL_FUNCTIONS were installed, checked and confirmed the proper functions were inside, and prefixed it to ensure that the file was not overriden. However when I try to use it I get the following error:

[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!
User avatar
GrovyleXShinyCelebi
 
Posts: 294
Joined: 12 Jun 2013, 18:23
Has thanked: 14 times
Been thanked: 37 times

Re: General DotP 2014 Coding Questions

Postby thefiremind » 18 Jan 2014, 10:32

GrovyleXShinyCelebi wrote:[lua] [string "TESTCARD2_TITLE (AVAILABILITY)~0x00000164"]:2: attempt to call global 'TFM_SuspendCheck' (a nil value)
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?
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times

PreviousNext

Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 44 guests


Who is online

In total there are 44 users online :: 0 registered, 0 hidden and 44 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 44 guests

Login Form