As far back as 2001 I had thought about what it might mean for a game to have a "magic programming" system, where spells would be programs that interact with the world. I've since encountered the concept in many different contexts, a few examples:
- Rick Cook's Wizard's Bane centers around a systems programmer transported to a fantasy world, who builds up a powerful system for constructing magic spells along the lines of Forth.
- In True Names, Vernor Vinge builds the predecessor to Gibson's cyberspace as a fantasy world; in this metaphorical virtual world the closest analog to programming is sorcery.
- There is precedent in the magic system of true names and words of power which make up Ursula Le Guin's Earthsea, drawing on older traditions, indeed Vinge credits Le Guin in his introduction.
- Jack Vance's Dying Earth treats magic as advanced mathematics, complete with formulas named after their discoverers.
- The textbook Structure and Interpretation of Computer Programs, as well as the accompanying lectures, refer to computer programs as a kind of magic spell, particularly regarding the mystical connotations of a language that can describe itself.
Although magic is a supernatural and arcane system, we get the feeling that people can bring the structuring power of linguistics, mathematics, and programming to bear in order to bend reality to their will. In essence this makes for a scientific treatment of a magical world, with the magician's art akin to engineering. Wizard's Bane describes the protagonist's efforts in discovering and building his own magic system. Rather than attempting to master the vast, complicated, and error-prone spells that master wizards spend their lives developing, he convinces a reluctant sorceress to teach him a few trivial but reliable spells. He started with a spell to cause a light puff of air, and caused it to be cast automatically and in parallel, creating a strong wind. While this may seem like an obvious step, the system required to make a spell that "runs itself" drew on his knowledge of programming environments, which was totally alien to the traditional spellcasters.
In the realm of games, the SNES RPG Rudra no Hihou implements magic spells not as items to be bought or picked up, but as words that can be typed in and modified to produce various magical effects. New "root words" for spells are found in in-game books or notes, or in conversations with NPCs, and various suffixes can make the spell more or less powerful, affect one or all enemies, or even change the behavior entirely. While this is not quite at the level of programming, it is a kind of language, and it is fundamentally different from the common RPG magic system. Rather than the knowledge of a spell being a property of a character in the game, as are other traits such as intelligence or strength or proficiency with weapons, it becomes a real piece of knowledge that the player can learn, write down, and discover.
As Raph Koster insists,
with games, learning is the drug. It is universally the case that the player acquires knowledge to help him progress in the game, because a well-designed game provides ample opportunities for learning and requires learning for progression. On this level, making a magic system part of the player's knowledge is no different from his memory of the layout of a level, or the peculiar physics of rocket jumping. The difference comes in considering the magic as a language, a system that can be used to construct new and elaborate conceptual structures.
Contrast a magic programming system to the idea of cheat codes, which have a similar "knowledge is power" property. Cheat codes are entered as a series of symbols, so there is a superficial similarity, and they may be discovered in-game. Yet the symbols that make up cheat codes do not make up a language, you cannot write new things with them, and studying them does not reveal a grammar. Cheat codes are not a "productive" system, as described in this passage from Thomas W. Malone's What Makes Things Fun to Learn:
The productive principle suggests that learning is more efficient in environments that are structured in such a way that students can make deductive inferences or probable inferences about parts of the environment that they have not yet observed. … the periodic table is a more "productive" way of arranging information about chemical elements than alphabetical order would be, and phonetic alphabets are more "productive" than ideographic writing systems like Chinese. (p 7)
Limited as Rudra no Hihou's magic system is, it has the fantastic property of allowing you to learn the rules of the system, so as to generate new spells. Indeed it encourages this in several ways: As soon as a spell is entered in the spellbook, the game reports what the spell will do. Tips are given throughout the game in the form of "try adding this suffix", clarifying how the components fit together. It does not go quite as far as I would like, however: it tries to keep the magic system somewhat mysterious, magic is but one corner of a much larger game, and it is necessary to write things on paper in order to work out and maintain a large library of spells.
Returning to cheat codes, my analysis above is incomplete, because in certain cases cheat codes are very strongly productive. If the codes are present as strings in the game's executable, then searching for one known string may identify other codes stored nearby. If one is capable of reverse engineering a game to identify a cheat code subsystem, that knowledge can be applied to other games as well. This is to say nothing of systems such as the Game Genie or Action Replay, wherein the codes do actually function as a language, and they can provide deep insight into the game structure.
Consider a fantasy game in which the game world is written in the language of magic, in an echo of the Earthsea myth. In accomplishing tasks in the game world, the player learns magic spells. A productive language allows the player to use this knowledge to deduce new spells, but also to learn more about the structure of the world. This can allow him to open new paths, and peer into the systems we build for him to explore.