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

products, and this trend is likely to continue well into the future. This has
become a big selling point for many games. Probably the two best known
examples in recent times are Epic Games’ Unreal Tournament 2004 (and
UT2003) and BioWare’s Neverwinter Nights. Both provide the gamer with
a powerful scripting engine, enabling individuals and teams to create rich,
custom-built scenarios.
Now that you’ve seen some of the advantages of using scripting in your
games, let’s take a look at some specific examples of how scripting lan
-
guages have been used by game developers.
Dialogue Flow
One of the simplest and earliest uses of scripting languages in games is to
manage the vast amounts of dialogue found in RPG type games. In these,
scripts are used to control the flow of dialogue between a character and the
player. A typical script might look something like this:
** Dialogue script 1 for Eric the Gross Nosed **
FUNCTION DialogueWithGrossNosedEric(Player plyr)
Speak(“Welcome stranger. What brings thee amongst us gentle folk?”)
int reply = plyr.SpeakOption(1, “Yo dude, wazzup?”,
2, “I want your money, your woman, and that chicken”)
IF reply == 1 THEN
Speak(“Wazzuuuuuup!”)
ELSE IF reply == 2 THEN
Speak( “Well, well. A fight ye wants, is it? Ye can’t just go around these parts demandin’ chickens
from folk. Yer likely to get that ugly face smashed in. Be off with thee!”)
END IF
END FUNCTION
This sort of script would be called by the main game code on the occur
-
rence of a specific event. In this example, it would be the player entering
the vicinity of Eric the Gross Nosed. Utilizing scripts in this way makes it
easy for game designers to write humongous amounts of dialogue quickly
and easily.
There’s no need to stop at just dialogue. Scripts can be written to control
a characters actions and the camera positioning, and handle sounds and
animation, providing a kind of…
To Script, or Not to Script, That Is the Question | 253
What a Scripting Language Can Do for You

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