O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Compiled scripts are scripts that have been converted by the scripting lan-
guage’s compiler into a form of machine code the VM can execute directly.
This machine code, or byte code, is completely platform independent
because it’s not been compiled to run on a type of machine, it’s been com-
piled to run inside the virtual machine. Compiled scripts run faster, are
smaller in size, and are therefore quicker to load. An additional benefit is
that byte code is illegible to humans and therefore less prone to misuse by
the end user.
What a Scripting Language Can Do for You
Scripting languages can assist the development process in many ways:
They can be used as a quick and easy way of reading variables and
game data from initialization files. There’s no need to write a parser of
your own — just plug in the scripting language and off you go. And
although this is a little like using a snowplow instead of a shovel to shift
the snow from your driveway, it makes the job quick and easy and you
don’t get blisters on your hands.
They can save time and increase productivity. As game projects grow
in size, so too does the time required to build them. Full engine compiles
frequently take several minutes to complete and in some instances, well
over an hour. This can be a nightmare for the AI programmer who has just
implemented his latest brainwave and needs to test its performance before
moving on to the next stage of his master plan. The last thing you want to
do is sit around drinking yet another coffee, drumming the rhythm to the
“Ace of Spades” on your thighs while your machine chugs away. However,
if some of the AI logic is transferred from C++ to a script, changes can be
made easily and quickly without need for recompilation. In projects where
To Script, or Not to Script, That Is the Question | 251
What a Scripting Language Can Do for You
Screenshot 6.3. Impossible Creatures
Ó Relic Entertainment, Inc.
Content removed due to copyright restrictions
you know in advance that compile times are going to be a daily thorn in
your side, it’s worth considering scripting the majority of the AI decision
logic while the game is in development, and then transferring the speed-
critical stuff back to C++ prior to shipping. This keeps your productivity
and cranial juices flowing while simultaneously reducing caffeine jitters to
a minimum, which means it’s good for the heart as well as the cash flow.
They can increase creativity. Scripting languages usually operate at a
higher level than languages such as C++ and utilize syntax that is more
intuitive to non-programmers. This is advantageous because it allows other
members of the development team like level designers, artists, and produc-
ers to make adjustments to the gameplay (or any other aspect of the design)
without having to pester you every few minutes. They are able to do this
from the comfort of their own workstations, making as many adjustments
as they like to the exposed functionality of the AI without any need for
major rebuilds. This is beneficial to both productivity and creativity. The
former promotes experimentation and the latter enables you, the program-
mer, to work uninterrupted. Since this ability to play with the engine allows
any interested members of the development team to get their hands dirty
and fool around with the gameplay, giving them a greater sense of involve-
ment in the final product, it’s also good for morale.
They provide extensibility. In recent years there has been an upsurge in
players customizing games to create “mods.” Some of these mods are
unrecognizable from the original game because just about everything has
changed. The maps are different, the textures are unique, the weapons more
kick-ass, and the bad guys badder. Using a scripting language, it’s possible
to expose as much or as little of your game engine as you like, putting its
power directly into the hands of the mod makers. Increasingly, game devel-
opers are electing to give game players the opportunity to tinker with their
252 | Chapter 6
What a Scripting Language Can Do for You
Screenshot 6.4. Neverwinter Nights
Ó Atari/BioWare
Content removed due to copyright restrictions

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required