310 likes | 664 Views
Scripting. Ian P. Warfield CSE 497 - Topics on AI and Computer Game Programming October 25, 2004. Definition of Scripting. “ Scripting is the technique of specifying a game’s data or logic outside of the game’s source language.” – AI Game Programming Wisdom 2
E N D
Scripting Ian P. Warfield CSE 497 - Topics on AI and Computer Game Programming October 25, 2004
Definition of Scripting • “Scripting is the technique of specifying a game’s data or logic outside of the game’s source language.” – AI Game Programming Wisdom 2 • “A script is a program that automates a sequence of tasks… Early script languages were often called batch languages or job control languages. – http://www.wordIQ.com/
Advantages of Scripting • Game designers can write a lot of code for comparatively little effort • The scripting language can be designed specifically for the game under development, minimizing programming overhead • Scripts can be changed more easily than code
Advantages of Scripting • The more “moddable” your game is, the more people will buy it and the longer it will be marketable • If your game is popular enough, you can license your game engine to other developers • This business practice was spurred by the popularity of DOOM and Quake • Later games, such as Quake 3, Unreal, and DOOM 3 were designed specifically with this in mind
Disadvantages of Scripting • Nonprogrammers are required to program • Creating a custom scripting language is an extra step in the game development • The new language requires technical support and tools for debugging
Levels of Scripting • Level 0: Everything hard-coded in the source language • Level 1: Stats and locations specified in files • Level 2: Scripted non-interactive cutscene sequences • Level 3: Lightweight logic specified by tools or scripts, as in a trigger system • Level 4: Heavy logic in scripts that rely on core functions in the game engine • Level 5: Everything coded in scripts
Level 0: Hard-coded AI • Quickest to code, especially for small development teams or small projects • Scales very poorly; difficult to debug complex programs • Best suited for simple projects • Used in the earliest games such as Pong, Space Invaders, and Pac-Man
Level 1: Data Specified in Files • The player’s character, his enemies, the surrounding objects, and the goals all remain the same – only the arrangement is different • Scales extremely well in terms of game size but poorly in terms of game extensibility • Suitable for repetitive games with multiple levels • Used in early games such as Super Mario, Lode Runner, and Chip’s Challenge
Level 2: Scripted Cutscenes • Scripted cutscenes were actually quite rare until recently • Game designers traditionally prefer to pre-render cutscenes • Game engines did not have the power to render cutscene-quality graphics on-the-fly • So this is a little out-of-order
Level 2: Scripted Cutscenes • Now that game engines can render high quality graphics, scripted cutscenes are preferred • Cost and file size are both dramatically improved • Scripting also allows for adaptive cutscenes depending on story developments • Used in games such as Half-Life and Star Trek Voyager: Elite Force
Level 3: Trigger System • Functions are coded in C/C++ and linked by scripts • Scripts consist of “events” which trigger actions or possibly other events • Offers best balance of flexibility, ease of use, power, speed, and extensibility • Used in Freespace 2
Level 4: Heavy Script Logic • Only the core functions are coded in C/C++; most of the logic is in the script • Handle interesting events and character AI, but let the game handle physics, etc. • Offers large degree of flexibility while still providing a solid code foundation • Used in Unreal and Half-Life
Level 5: Everything in Scripts • The bare minimum of functions are coded in C/C++; everything else is scripted • Scripts resemble full-fledged programming languages • Offers maximum degree of flexibility but carries most of the same risks as conventional programming • Used in Jax and Daxter
Level 5: Everything in Scripts • Nearly all the run-time code written in GOAL (similar to LISP) • Code could be modified on-the-fly • No need to recompile the engine • Debugging took much less time • There were setbacks, however • Compiler took a long time to develop • Developers had to create their own debugging and support utilities • Programming in GOAL required adjustment from C/C++
Achieving a Balance • Most games are designed for scripting at Level 3 or Level 4 • Flexibility of scripting combined with power of C/C++ • Libraries, tools, profilers, debuggers are still available
Achieving a Balance • Level 3 and Level 4 can be thought of as “declarative” and “imperative” models, respectively • Declarative – program in terms of “what” needs to be accomplished • Imperative – program in terms of “how” to accomplish it
Declarative Model • No implicit state, no assignments • Expression evaluation instead of instruction sequencing • Recursion instead of loops • Tends toward “functional” programming paradigm, used in LISP
Declarative Model • Sample code: ( when ( is-destroyed “NTD Repulse” ) ( send-message “Well done” ) )
Imperative Model • States defined in variables • Variable modification through explicit assignment • Loops and iterative sequences of statements
Imperative Model • Sample code: ship *ship_ctr; for (ship_ctr = GET_FIRST(ship_list); ship_ctr != GET_LAST(ship_list); ship_ctr = GET_NEXT(ship_ctr)) { if (strcmp(ship_ctr->name, “NTD Repulse”) == 0) { if (ship_ctr->flags & SF_DESTROYED) { message_queue_add(“Well done”); break; } } }
A Level 3 Demonstration • FRED – the FReespace EDitor • Visit the Freespace 2 community forums at http://www.3dap.com/hlp/
Summary • Core C/C++ functions do the hard work and the script provides the creative element • Scripting provides the flexibility and moddability your game needs to be successful • The write-time advantage far outweighs the run-time and development-time disadvantage • Choose an appropriate level of scripting that balances flexibility and user-friendliness with the power of your underlying game engine
Sources • Combs, Nathan, and Jean-Louis Ardoint. Declarative versus Imperative Paradigms in Games AI. http://www.roaringshrimp.com/. • Definition of Script (computer programming). http://www.wordIQ.com/. • Game Engine. http://www.wikipedia.com/. • Niestadt, Jan. Implementing a Scripting Engine. http://www.flipcode.com/. • Patel, Amit. Amit’s Game Programming Information. http://www-cs-students.stanford.edu/~amitp/. • Rabin, Steve, et al. AI Game Programming Wisdom 2. Hingham: Charles River Media, Inc., 2004. • Scripting. http://www.wikipedia.com/. • Simpson, Jake. Game Engine Anatomy 101. http://www.extremetech.com/. • Sweeny, Tim. UnrealScript Language Reference. http://unreal.epicgames.com/. • White, Stephen. Postmortem: Naughty Dog's Jak and Daxter: the Precursor Legacy. http://www.gamasutra.com/.