Card source guide
Implementations are a small, literal JavaScript expression that the backend evaluates with
its own safe interpreter. It is never run as JavaScript: only the names below exist. The
editor and the compiler use the same two-way format. Use Draft with AI for
a first pass, then review and save.
Shape
Export the card's type line and an array of abilities with
card(typeLine, [...]). A leading // Card [status] comment is
optional and ignored. Multi-face cards export
faces(face('Name', 'Type line', [...]), ...) in card order.
export default card('Creature — Human Cleric', [
keywords('Flying', 'Ward {2}'),
triggered(when.enters(each(permanents.other().withType('creature'))), [
gainLife(you, 1),
]),
activated([tapCost()], [
addMana(you, mana('{G}')),
]),
])
export default faces(
face('Front', 'Instant', [spell([draw(you, 2)])]),
face('Back', 'Creature — Human', [keyword('Flying')]),
)
Plain export default [...] is still accepted and uses the Scryfall type line.
Effect lists also accept callbacks: () => draw(you, 1) for one effect,
or () => { draw(you, 1); gainLife(you, 1) } for several. Arrays remain
valid; the formatter emits callbacks.
Abilities
| Call | Example |
triggered(event, [effects], options) | triggered(when.dies(self), [draw(you, 1)]) |
activated([costs], [effects], options) | activated([manaCost('{2}'), tapCost()], [...]) |
staticAbility([effects], options) | staticAbility([staticPump(each(creatures.youControl()), 1, 1)]) |
spell([effects], options) | An instant or sorcery. |
keyword(name, value) | keyword('Ward', '{2}') |
keywords(...names) | keywords('Flying', 'Trample') |
additionalCost([costs]) | additionalCost([payLife(2)]) |
chapter(['I', 'II'], [effects]) | Saga chapters. |
unsupported(reason, text) | Preserve the oracle text when it cannot be expressed. |
Options include { condition, optional }; activated abilities also accept
timing: 'sorcery' and activationsPerTurn.
Selectors and targets
Start from permanents, cards or creatures and chain
filters: withType, withSubtype, withSupertype,
withColor, withKeyword, youControl,
other, tapped, token, powerAtLeast,
manaValueAtMost, named, inZone.
target(permanents.withType('creature').other().youControl())
each(creatures.withColor('red').withKeyword('flying'))
pick(cards.withType('land'), { upTo: 2 })
targetSpell(permanents.withType('instant'))
divided(3, creatures.attacking())
self, triggerSubject, previousTarget, anyTarget, targetPlayerOrPlaneswalker
Values: numbers, X, itsPower, itsToughness,
count(selector), cardsInHand(you),
totalPower(selector), eventAmount().
Effects and costs
damage(target(creature), 3)
draw(you, 2)
gainLife(you, 1)
createToken(you, 1, token({ types: ['creature'], subtypes: ['goblin'], colors: ['red'], power: 1, toughness: 1 }))
putCounters(target(creature), '+1/+1', 2)
destroy(target(creature))
addMana(you, mana('{G}{G}'))
search(you, cards.withType('creature'), 1, { destination: 'battlefield', shuffle: true })
pump(each(creatures.youControl()), 1, 1, untilEndOfTurn)
ifThen(youControl(permanents.withType('artifact'), 3), [draw(you, 1)])
modal(1, 1, [[draw(you, 2)], [gainLife(you, 3)]])
Costs are separate: manaCost('{2}{U}'), tapCost(),
sacrificeSelf(), payLife(3),
discardCost(1), removeCountersCost('+1/+1', 1).
Durations: permanent, untilEndOfTurn,
untilYourNextTurn, untilEndOfYourNextTurn,
untilEndOfCombat, whileSourceOnBattlefield.
Triggers, statics and conditions
triggered(when.attacks(self), [
createToken(you, 1, token({ types: ['creature'], subtypes: ['goblin'], colors: ['red'], power: 1, toughness: 1, tapped: true })),
])
triggered(when.upkeep(you), [
ifThen(youControl(permanents.withType('artifact'), 3), [draw(you, 1)]),
])
staticAbility([
staticGrant(each(creatures.youControl()), 'Flying'),
])
Common triggers: when.enters, when.dies,
when.attacks, when.upkeep, when.endStep,
when.cast, when.dealsDamage. Common conditions:
yourTurn(), youControl(selector, n), wasKicked(),
ifYouDo(), otherwise(). Always check the compiled result after
saving.
When the syntax cannot express it
Never guess a wrong effect. Preserve the oracle text and leave it unsupported:
unsupported('modal bullet outside a modal block', 'Choose one — ...')
The full reference lives in backend/docs/card-effects.md.