INSYG
  • INSYG
  • Newbie Topic Starter
2014-04-26T20:38:47Z
My card reads as such:
Quote:

When this card is targeted for an attack: You can Special Summon one "___ Token" (Warrior-Type/DARK/Level 3/ATK 0/DEF 0); Change the attack target to another monster you control. The ATK and DEF of the "___ Token" are equal to half the attacking monster's ATK. When a Token you control is destroyed by battle, this card gains ATK equal to the Token's ATK.



I've been borrowing lines of code from other cards (specifically "Caam, Serenity of Gusto", "Battlin' Boxer Glassjaw", and some "Mecha Phantom Beast" monster).
Right now, my code looks like this:
Quote:

function c50020004.initial_effect(c)
local e1=Effect.CreateEffect(c)
e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
e1:SetCode(EVENT_BE_BATTLE_TARGET)
e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
e1:SetRange(LOCATION_MZONE)
e1:SetCost(c50020004.cost)
c:RegisterEffect(e1)
end
function c50020004.cost(e,tp,eg,ep,ev,re,r,rp,chk)
if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end
if Duel.IsPlayerCanSpecialSummonMonster(tp,31533705,0x0,0x0,0,0,3,RACE_WARRIOR,ATTRIBUTE_DARK) then
local token=Duel.CreateToken(tp,67922703)
Duel.SpecialSummon(token,0,tp,tp,false,false,POS_FACEUP)
end
end



When my monster is summoned, YGOPRO tells me:
Quote:

15: Action is not allowed here.


Line 15 being:
Quote:

local token=Duel.CreateToken(tp,67922703)



What can I do to fix this?
Vertex
2014-04-27T09:09:58Z
When writing a cost or target function, you need to make note of the chk variable, it is 0 if the game is checking if the targeting or payment can be done, and 1 if it is actually executing the function. The game always checks first, and the error is caused when you are trying to actually do stuff during the check. The first thing in your function needs to be

if (chk==0) then
return --true/false if you can pay the cost or not
end
--rest of function here

As noted, it should return true or false if you can pay the cost or not (in this case, if you can summon the token or not), then after the function (when chk is confirmed to be 1) you can actually put the code to summon the token.