Monday, September 7, 2009

Scripting Cards with Cards.txt

At first cards.txt was only used to create simple creatures that had "standard" keywords like vigilance and trample but Rob and other people from the forums have contributed code to expand the types of cards that can be added to cards.txt. The best way to understand this is to have a look at Shock, Volcanic Hammer, and Lightning Bolt.

Lightning Bolt
R
Instant
spDamageCP:3

Volcanic Hammer
1 R
Sorcery
spDamageCP:3

Shock
R
Instant
spDamageCP:2

Each of these cards deals damage a creature or player and their only difference is their speed (sorcery versus instant) and the amount of damage. By "scripting" these cards it allows MTG Forge to be more flexible. Cards similar to Shock and Lightning Bolt can be easily added without having to add more Java code.

And this is just a tip of the iceberg. Cards.txt supports a number of other special words that allows to players draw cards or destroy creatures. While all cards cannot be scripted be scripted because they are too unique and different, like Warp World, many cards can be implemented this way.

Scripting Magic cards like this is the wave of the future. I also believe that the Wagic project uses Lua to script Magic cards. (Wagic lets you play Magic on your PSP or Windows machine.) A little game called World of Warcraft also uses Lua. Lua can be "embedded" in other languages so the programmer doesn't have to write a new scipting language from scratch (which is hard).

3 comments:

Shing said...

I've tested Wagic a little and while it does seem like it allows for addition of cards much more quickly, the AI seem to suffer similar problems to Forge. I've stopped playing it because the user interface is a bit tedious because it was designed for the PSP(I played the PSP version). Having the ability to actually click the cards with a mouse and sort through cards in the deck builder makes Forge vastly superior in terms of the user interface.

Forge said...

Wagic is designed for a PSP so it is a little hard to use it on Windows, I suggest that you get a joypad and map all of the buttons to it.

contactos barcelona said...

Quite helpful material, thank you for this post.