Duel.GetFirstTarget
Signature
Duel.GetFirstTarget() -> Card|nilDescription
Returns the first target card currently recorded for the resolving Chain. If multiple target cards were recorded, the remaining target cards are returned as additional values in recorded order. For effects that target several cards and affect only the remaining valid targets, Duel.GetTargetsRelateToChain is usually clearer.
How To Use It
Use this during resolution when the effect selected exactly one target card.
The binding returns all stored Chain targets as Lua return values; scripts commonly keep the first one when the effect selected exactly one card. Always check that the returned card still exists and is still related to the resolving effect before moving, destroying, equipping, or changing it:
local tc=Duel.GetFirstTarget()
if tc and tc:IsRelateToEffect(e) then
Duel.SendtoHand(tc,nil,REASON_EFFECT)
endFor multiple targets, use Duel.GetTargetsRelateToChain() when you need the group of targets that are still related to the resolving Chain.
Related Functions
Returns
Card|nil- First recorded target card, followed by any additional target cards as extra Lua return values. No value is returned when the current Chain has no target cards.
Source
D:\Programs\GitHub\ygopro-core\libduel.cpp:4949
Guided Examples
Learn how to use this function in context:
- Client UI And Prompt Behavior
- Common Script Errors And Debugging
- First Scripts To Study
- Quick-Play Spells
- Selection And Group Handling
- Targeting Flow
Used By
Generated from the local Scripts/ folder and cards.cdb.
- Detected in 4747 indexed script(s).
- Search this function in the Script Explorer with
Duel.GetFirstTarget.
Script Examples
Salamandra with Chain (62091148)
Source: Scripts/c62091148.lua
local c=e:GetHandler()
if not c:IsRelateToEffect(e) or c:IsStatus(STATUS_LEAVE_CONFIRMED) then return end
local tc=Duel.GetFirstTarget()
if tc:IsRelateToEffect(e) and tc:IsFaceup() and Duel.Equip(tp,c,tc) then
local e1=Effect.CreateEffect(c)Pendulum Evolution (55795155)
Source: Scripts/c55795155.lua
end
function c55795155.atkop(e,tp,eg,ep,ev,re,r,rp)
local tc=Duel.GetFirstTarget()
if tc:IsRelateToEffect(e) then
local e1=Effect.CreateEffect(e:GetHandler())Surprise Fusion (35167375)
Source: Scripts/c35167375.lua
local c=e:GetHandler()
local race,att=e:GetLabel()
local ec=Duel.GetFirstTarget()
if ec:IsRelateToChain() and ec:IsFaceup() and ec:IsType(TYPE_MONSTER) then
local cres=ec:GetRace()~=race or ec:GetAttribute()~=att