Game Scripting Matery

An Introduction to Scripting

What is Scripting

The first thing you need is the game engine; something that allows players to walk around and explore the game world, interact with characters, and do battle with enemies. Next up you're going to need graphics. Now on to music and sound.

The content separate a demo from the next platinum seller.

Structured Game Content -- A Simple Approach

The first and perhaps most obvious approach is to have the programmer manually code all this data into the engine itself.

Each item in your game needs a unique description that tells the engine how it should look and function whenever the player uses it. You might create a struct that will describe an item, and then create an array of these structures to hold all of them.

teypedef struct _Item{  
    char * pstrName; // Item's name
    int iType;  // Item type
    int iPrice;  // Item's price
    int iPower;  // how powerful
} Item;

iType is the general type of the item, which the engine needs in order to know how it should function when used. It's an integer, so a list of constants that describe its functionality should be defined:

const HEAL = 0;  
const MAGIC_RESTORE = 1;  
const ARMOR_REPAIR = 2;  
const TELEPORT = 3;  

Now that the game's internal structure for representing items has been established, it needs to be filled. A case of example:

const MAX_ITEM_COUNT = 128;

Item ItemArray[MAX_ITEM_COUNT];

ItemArray[0].pstrName = "Health Potion Lv 1";  
ItemArray[0].iType = HEAL;  
ItemArray[0].iPrice = 20;  
ItemArray[0].iPower = 50;  

The problem with all of this constant recompilation is mostly a physical issue; it wastes a lot of time, repeats a lot of processing unnecessarily, and so on.

Improving the Method with Logical and Physical Separation

The situation in a nutshell is that you need an intelligent, highly structured way of separating your code from your game content.

The game's only connection with this data is the code that reads it from the disk. Ther're loaded at runtime.

The Perils of Hardcoding

Hardcoding is the practice of writing code or data in a rigid, fixed or hard-to-edit sort of way. It is almost always something to avoid.

Storing Functionality in External Files

Scripting actually lets you write code outside of your engine, load that code into the engine, and execute it. These two types of code are separate -- scripts use their own compiler and have no effect on your engine.

How Scripting Actually Works

One of the most popular solution to this problem literally involves designing and implementing a new language from the ground up. This language is called a scripting language.

The first step in explaining how scripting works is to make sure you understand how programming works, from start to finish.