it’s common practice to place many of the constants in a separate initializa-
tion file and create code to read and parse that file. This way, if you want to
change some values, you don’t need to recompile the project; you only
have to change the values in the initialization/configuration file — usually
a simple text file. You may be surprised to know the use of an initialization
file like this is a rudimentary form of scripting and the text the initialization
file contains is a very basic scripting language.
A more advanced scripting language increases the interaction between
the script and the executable, enabling you to not only initialize variables
but to create game logic or even game objects, all from one or more script
files. These script files are run from within your program by something
called a virtual machine, or VM for short. I’m not going to go into the
details of virtual machines in this book — it’s too low level and I don’t
think it’s appropriate — but it helps to think of a VM as an emulated CPU
sitting snugly inside your game’s executable (your web browser, for exam-
ple, uses a virtual machine to run Java code). You write functions in the
syntax of the scripting language, which are read and then run inside the
virtual machine. The beauty of scripting is that the virtual machine can
communicate with the language inside which it resides (in our case C++),
enabling data to easily be passed back and forth.
Scripts can either be interpreted or compiled. An interpreted script exists
in the same format in which it is written — the human readable scripting
language itself — and is read, parsed, and executed line by line by some-
thing called an interpreter. As this can be a slow process to do on-the-fly,
some interpreted scripting languages automatically compile the script
before it’s executed. Another problem with interpreted scripts is that they
can easily be understood and edited by game players who like nothing
better than to give themselves an unfair advantage.
250 | Chapter 6
Just What Is a Scripting Language?
Screenshot 6.2. Black & White
Ó Lionhead Studios Limited
Content removed due to copyright restrictions