Game Scripting


  • Scripting Cookbook: What You Need
  • Implementing Touch and Release Notifications
  • Game Object Listeners
  • Scripting
  • Delayed Events
  • Putting It All Together
  • Enhancements
  • Summary

You walk into a dark room and flip a switch. A second later, a door opens across the way and light comes pouring in. But you don't get a chance to walk through the door—a couple of seconds later, the door slams shut and the room grows dark again. The trick? The door is only open for a few seconds, so you've got to flip the switch and run to get through the door. How would you implement something like this in a game? That's what you'll solve in this chapter. Every level in a typical game has a certain amount of unique code for environment interaction, and those unique bits are what add a lot of value to a game, making it more fun, interesting, and exciting. But programmers aren't the only ones who will be creating these unique environment interactions—in a lot of cases, level designers will do most of it. So in this chapter, we go over how to connect your game objects to external scripts that are easy to write. This way, level designers won't need to know how to implement an interface or compile—all they'll need to know is how to write simple functions. Also, allowing anyone to create levels and write scripts opens up room for users to create their own content or even make their own mods for a game. A mod is simply a modification of an existing game—for example, Counter-Strike is a Half-Life mod. Besides scripting, this chapter covers triggers (something that causes an event to occur) and delayed events (performing tasks after a certain delay).