• Save
State-Based Scripting in Uncharted 2: Among Thieves
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

State-Based Scripting in Uncharted 2: Among Thieves

on

  • 14,080 views

 

Statistics

Views

Total Views
14,080
Views on SlideShare
8,367
Embed Views
5,713

Actions

Likes
16
Downloads
0
Comments
0

9 Embeds 5,713

http://www.motordejuegos.net 5597
http://www.weebly.com 45
http://ndwww-ext.scea.com 38
https://twitter.com 17
http://www.naughtydog.com 5
https://kcw.kddi.ne.jp 4
http://webcache.googleusercontent.com 4
http://salazkin.com 2
http://agilethiefgame.jusst.us 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

State-Based Scripting in Uncharted 2: Among Thieves Presentation Transcript

  • 1. State-Based Scripting in Jason Gregory Generalist Programmer Naughty Dog, Inc.Monday, April 6, 2009
  • 2. Agenda • Introduction to game scripting • Extending the game object model • State script syntax • Case studies from Uncharted 2: Among Thieves • Implementation discussion • Summary and some tips Game
Developers
Conference
2009 2Monday, April 6, 2009
  • 3. Introduction to State Scripts 3Monday, April 6, 2009
  • 4. Brief History of State Scripts • Script system on Uncharted: Drake’s Fortune originally developed for in-game cinematics (IGCs) • Evolved into general gameplay scripting system Game
Developers
Conference
2009 4Monday, April 6, 2009
  • 5. Brief History of State Scripts • UDF IGC system revamped for heavy use on Uncharted 2: Among Thieves • Inspirations:  GOAL language used on Crash and Jak series  State objects from God of War engine TM Game
Developers
Conference
2009 5Monday, April 6, 2009
  • 6. Why Script? • Scripting languages used in games since Quake C • Primary benefits of script:  Takes pressure off engineering team  Code becomes data—rapid iteration  Empowers content creators  Key enabler of mod community Game
Developers
Conference
2009 6Monday, April 6, 2009
  • 7. Why Script? • Scripting languages used in games since Quake C • Primary benefits of script: I
feel
empowered!  Takes pressure off engineering team  Code becomes data—rapid iteration  Empowers content creators  Key enabler of mod community Game
Developers
Conference
2009 6Monday, April 6, 2009
  • 8. Scripting Language Characteristics • Two kinds of game scripting languages:  data definition languages  runtime languages • Runtime scripting languages typically:  interpreted by virtual machine (VM)  simple and small—low overhead  accessible to designers and other “non-programmers”  powerful—one line of code = big impact Game
Developers
Conference
2009 7Monday, April 6, 2009
  • 9. Choice of Language • At Naughty Dog, we make heavy use of both data definition and runtime script  Both based on PLT Scheme (a Lisp variant) • Key benefits of Lisp-like languages:  Easy to parse  Data def and runtime code can be freely intermixed  Powerful macro system—easy to define custom syntax  Naughty Dog has a rich Lisp heritage—comfortable Game
Developers
Conference
2009 8Monday, April 6, 2009
  • 10. Choice of Language • Of course you don’t have to use Lisp! • Data definition languages:  custom text format,  Excel comma-separated values (.csv),  XML, ... • Runtime languages:  Python, Lua, Pawn (Small C), OCaml, F#, ... • Many popular engines already provide a scripting language:  Quake C, UnrealScript, C# (XNA), ... Game
Developers
Conference
2009 9Monday, April 6, 2009
  • 11. Extending the Game Object Model • Every game engine has some kind of game object model  Defines all object types in game world  Often (but not always) written in an object-oriented language • Scripting language often used to extend the native object model • Many ways to accomplish this... Game
Developers
Conference
2009 10Monday, April 6, 2009
  • 12. Game Object Model References • Rob Fermier, “Creating a Data Driven Engine,” GDC, 2002 • Scott Bilas, “A Data-Driven Game Object System,” GDC, 2002 (http://www.drizzle.com/~scottb/gdc/game-objects.ppt) • Alex Duran, “Building Object Systems: Features, Tradeoffs and Pitfalls,” GDC, 2003 • Doug Church, “Object Systems,” presented at a game development conference in Seoul, Korea, 2003 (http://chrishecker.com/images/6/6f/ObjSys.ppt) • Jason Gregory, “Game Engine Architecture,” AK Peters, 2009 (http://gameenginebook.com) Game
Developers
Conference
2009 11Monday, April 6, 2009
  • 13. Unreal’s Approach • UnrealScript tightly integrated with C++ object model  Single-root class hierarchy with some add-on components  Classes defined in UnrealScript (.uc)  C++ header file (.h) automatically generated  Implementation in C++ or entirely in UnrealScript Pawn.h Actor generate Pawn.uc Pawn.cpp Info Pawn Pickup ... implement implement Scout Vehicle ... Game
Developers
Conference
2009 12Monday, April 6, 2009
  • 14. Property-Centric / Componentized Designs • Property-centric design used on Thief, Dungeon Siege, Age of Mythology, Deus Ex 2 and others  Game object just a unique id (UID)  “Decorated” with various properties (health, armor, weaponry, etc.)  Property encapsulates data + behavior Armor:
Light Health:
200 Object Weapon:
BFG (UID) AI:
PlayerAlly Weapon:
Pistol Game
Developers
Conference
2009 13Monday, April 6, 2009
  • 15. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Process SsTrackGroupProcess SsProcess ProcessGameObject DynLight CameraControl ... Character SimpleEnOty ... ... Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 16. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root Objects
  host of add-on components that
update
 over
Dme Process SsTrackGroupProcess SsProcess ProcessGameObject DynLight CameraControl ... Character SimpleEnOty ... ... Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 17. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Objects
 with
transform
 and
mesh Process SsTrackGroupProcess SsProcess ProcessGameObject DynLight CameraControl ... Character SimpleEnOty ... ... Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 18. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Base
class
for
 all
characters Process SsTrackGroupProcess SsProcess ProcessGameObject DynLight CameraControl ... Character SimpleEnOty ... ... Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 19. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Simple
 animaDng
 Process object SsTrackGroupProcess SsProcess ProcessGameObject DynLight CameraControl ... Character SimpleEnOty ... ... Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 20. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Process SsTrackGroupProcess SsProcess ProcessGameObject DynLight CameraControl ... Character SimpleEnOty ... Manages
a
State
 Script
instance ... Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 21. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Process SsTrackGroupProcess SsProcess ProcessGameObject DynLight CameraControl ... Manages
a
 Character SimpleEnOty ... chunk
of
 running
script
 ... code Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 22. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Process SsProcess Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 23. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Process SsProcess SsInstance Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 24. Uncharted Engine’s Object Model • Uncharted class hierarchy:  relatively shallow, single-root  host of add-on components Process ProcessGameObject SsInstance DrawControl AnimControl ... Game
Developers
Conference
2009 14Monday, April 6, 2009
  • 25. Charter • World editor for Uncharted is called Charter  Place game objects  Edit object properties  Control level streaming Game
Developers
Conference
2009 15Monday, April 6, 2009
  • 26. Uncharted State Scripts • State scripts similar in many respects to property-centric model...  adds finite state machine (FSM) support  not specifically tied to “properties”  coarser-grained (one script per object) • More like scripted extension to existing entity type...  ... or a “director” that orchestrates actions of other entities Game
Developers
Conference
2009 16Monday, April 6, 2009
  • 27. Anatomy of a State Script • A state script is comprised of:  attributes  states • States define object’s behavior via runtime script code:  response to events  natural behavior over time (update event)  transitional actions between states (begin/end events) Game
Developers
Conference
2009 17Monday, April 6, 2009
  • 28. Anatomy of a State Script State
Script
1 Variables State
A State
Script
2 On Update Variables On Event1 State
C State
B On Begin On Begin On Event4 Game
Developers
Conference
2009 18Monday, April 6, 2009
  • 29. Anatomy of a State Script State
Script
1 Variables Event1 State
A State
Script
2 On Update Variables On Event1 State
C State
B On Begin On Begin On Event4 Game
Developers
Conference
2009 18Monday, April 6, 2009
  • 30. Anatomy of a State Script State
Script
1 Variables Event1 State
A State
Script
2 On Update Variables On Event1 State
C go
to
 On Begin State
B State
B On Begin On Event4 Game
Developers
Conference
2009 18Monday, April 6, 2009
  • 31. Anatomy of a State Script State
Script
1 Variables Event1 State
A State
Script
2 On Update Variables On Event1 State
C go
to
 On Begin State
B State
B On Begin Event4 On Event4 Game
Developers
Conference
2009 18Monday, April 6, 2009
  • 32. Instantiating a State Script • Attached to a native (C++) game object: Game
 Object  designers extend or modify native C++ object type State
Script
1  define entirely new object types Game
Developers
Conference
2009 19Monday, April 6, 2009
  • 33. Instantiating a State Script • Attached to a native (C++) game object: Game
 Object  designers extend or modify native C++ object type State
Script
1  define entirely new object types • Attached to a trigger region:  convex volume Trigger
Region  detects enter, exit and occupancy State
Script
2 Game
Developers
Conference
2009 19Monday, April 6, 2009
  • 34. Instantiating State Scripts SsProcess • Placed as stand-alone object: State
Script
3  “director” orchestrates actions of (stand‐alone) other objects (e.g. IGC) Game
Developers
Conference
2009 20Monday, April 6, 2009
  • 35. Instantiating State Scripts SsProcess • Placed as stand-alone object: State
Script
3  “director” orchestrates actions of (stand‐alone) other objects (e.g. IGC) • Associated with a task: Task
A  task = check point Task
B1 Task
B2  script manages associated task  orchestrates AI encounters Task
C State
Script
4  controls player objectives Task
D Game
Developers
Conference
2009 20Monday, April 6, 2009
  • 36. Instantiating State Scripts SsProcess • Placed as stand-alone object: State
Script
3  “director” orchestrates actions of (stand‐alone) other objects (e.g. IGC) • Associated with a task: Task
A  task = check point Task
B1 Task
B2  script manages associated task  orchestrates AI encounters Task
C State
Script
4  controls player objectives Task
D • Spawned by another state script Game
Developers
Conference
2009 20Monday, April 6, 2009
  • 37. State Script Syntax 21Monday, April 6, 2009
  • 38. Game
Developers
Conference
2009 22Monday, April 6, 2009
  • 39. State Script Syntax • State script defined as follows:  Don’t let Lisp syntax throw you!  Lisp syntax is all (parentheses) (define-state-script ("kickable-gate")  Think C/C++ { } blocks (state ("locked") • Parenthesized blocks highly ) ... context-sensitive in Lisp/Scheme (state ("opening") ... ) (state ("open") ... ) ) Game
Developers
Conference
2009 23Monday, April 6, 2009
  • 40. State Script Syntax • State script defined as follows:  Don’t let Lisp syntax throw you!  Lisp syntax is all (parentheses) (define-state-script ("kickable-gate")  Think C/C++ { } blocks (state ("locked") • Parenthesized blocks highly ) ... context-sensitive in Lisp/Scheme (state ("opening") ... ) (state ("open") ... ) ) Game
Developers
Conference
2009 23Monday, April 6, 2009
  • 41. State Script Syntax • State script defined as follows:  Don’t let Lisp syntax throw you!  Lisp syntax is all (parentheses) (define-state-script ("kickable-gate")  Think C/C++ { } blocks (state ("locked") • Parenthesized blocks highly ) ... context-sensitive in Lisp/Scheme (state ("opening") ... ) (state ("open") ... ) ) Game
Developers
Conference
2009 23Monday, April 6, 2009
  • 42. State Script Syntax • State script defined as follows:  Don’t let Lisp syntax throw you!  Lisp syntax is all (parentheses) (define-state-script ("kickable-gate")  Think C/C++ { } blocks (state ("locked") • Parenthesized blocks highly ) ... context-sensitive in Lisp/Scheme (state ("opening") ... ) (state ("open") ... ) ) Game
Developers
Conference
2009 23Monday, April 6, 2009
  • 43. Event Handler Blocks (define-state-script ("kickable-gate") (state ("locked") (on (event "kick") ... ;; handle "kick" event • Each state contains zero or more ) (on (begin) event handler blocks ... ;; do when state entered ) (on (update) ... ;; do every frame ) (on (end) ... ;; do when state exited ) ) Game
Developers
Conference
2009 24Monday, April 6, 2009
  • 44. Event Handler Blocks (define-state-script ("kickable-gate") (state ("locked") (on (event "kick") ... ;; handle "kick" event • Each state contains zero or more ) (on (begin) event handler blocks ... ;; do when state entered ) (on (update) ... ;; do every frame ) (on (end) ... ;; do when state exited ) ) Game
Developers
Conference
2009 24Monday, April 6, 2009
  • 45. Event Handler Blocks (define-state-script ("kickable-gate") (state ("locked") (on (event "kick") ... ;; handle "kick" event • Each state contains zero or more ) (on (begin) event handler blocks ... ;; do when state entered ) (on (update) ... ;; do every frame ) (on (end) ... ;; do when state exited ) ) Game
Developers
Conference
2009 24Monday, April 6, 2009
  • 46. Event Handler Blocks (define-state-script ("kickable-gate") (state ("locked") (on (event "kick") ... ;; handle "kick" event • Each state contains zero or more ) (on (begin) event handler blocks ... ;; do when state entered ) (on (update) ... ;; do every frame ) (on (end) ... ;; do when state exited ) ) Game
Developers
Conference
2009 24Monday, April 6, 2009
  • 47. Event Handler Blocks (define-state-script ("kickable-gate") (state ("locked") (on (event "kick") ... ;; handle "kick" event • Each state contains zero or more ) (on (begin) event handler blocks ... ;; do when state entered ) (on (update) ... ;; do every frame ) (on (end) ... ;; do when state exited ) ) Game
Developers
Conference
2009 24Monday, April 6, 2009
  • 48. Runtime Script Code • Runtime script code inside (on ...) (state ("locked") (on (begin) blocks [print-string "Starting idle!"] [animate "self" "locked-idle"] • Simplified Scheme/Lisp ) (on (event "kicked")  Most “commands” are native calls [when [lock-broken?] into C++ code [print-string "BAM!"] ]  Conditional expressions [if [task-complete? "wave2"] [print-string "Complete!"]  Simple looping via label/goto [print-string "NOT!!!"] ] ) ) Game
Developers
Conference
2009 25Monday, April 6, 2009
  • 49. Runtime Script Code • Runtime script code inside (on ...) (state ("locked") (on (begin) blocks [print-string "Starting idle!"] [animate "self" "locked-idle"] • Simplified Scheme/Lisp ) (on (event "kicked")  Most “commands” are native calls [when [lock-broken?] into C++ code [print-string "BAM!"] ]  Conditional expressions [if [task-complete? "wave2"] [print-string "Complete!"]  Simple looping via label/goto [print-string "NOT!!!"] ] ) ) Game
Developers
Conference
2009 25Monday, April 6, 2009
  • 50. Runtime Script Code • Runtime script code inside (on ...) (state ("locked") (on (begin) blocks [print-string "Starting idle!"] [animate "self" "locked-idle"] • Simplified Scheme/Lisp ) (on (event "kicked")  Most “commands” are native calls [when [lock-broken?] into C++ code [print-string "BAM!"] ]  Conditional expressions [if [task-complete? "wave2"] [print-string "Complete!"]  Simple looping via label/goto [print-string "NOT!!!"] ] ) ) Game
Developers
Conference
2009 25Monday, April 6, 2009
  • 51. Runtime Script Code • Runtime script code inside (on ...) (state ("locked") (on (begin) blocks [print-string "Starting idle!"] [animate "self" "locked-idle"] • Simplified Scheme/Lisp ) (on (event "kicked")  Most “commands” are native calls [when [lock-broken?] into C++ code [print-string "BAM!"] ]  Conditional expressions [if [task-complete? "wave2"] [print-string "Complete!"]  Simple looping via label/goto [print-string "NOT!!!"] ] ) ) Game
Developers
Conference
2009 25Monday, April 6, 2009
  • 52. User-Defined Functions (defun verbose-anim ((anim string)) [print-string "Starting " anim] [animate "self" anim] ) • Script functions can be defined and called by script programmer (define-state-script ("kickable-gate") (state ("locked") (on (begin) [verbose-anim "locked-idle"] ) ) ... ) Game
Developers
Conference
2009 26Monday, April 6, 2009
  • 53. User-Defined Functions (defun verbose-anim ((anim string)) [print-string "Starting " anim] [animate "self" anim] ) • Script functions can be defined and called by script programmer (define-state-script ("kickable-gate") (state ("locked") (on (begin) [verbose-anim "locked-idle"] ) ) ... ) Game
Developers
Conference
2009 26Monday, April 6, 2009
  • 54. User-Defined Functions (defun verbose-anim ((anim string)) [print-string "Starting " anim] [animate "self" anim] ) • Script functions can be defined and called by script programmer (define-state-script ("kickable-gate") (state ("locked") (on (begin) [verbose-anim "locked-idle"] ) ) ... ) Game
Developers
Conference
2009 26Monday, April 6, 2009
  • 55. User-Defined Functions (defun verbose-anim ((anim string)) [print-string "Starting " anim] [animate "self" anim] ) • Script functions can be defined and called by script programmer (define-state-script ("kickable-gate") (state ("locked") (on (begin) [verbose-anim "locked-idle"] ) ) ... ) Game
Developers
Conference
2009 26Monday, April 6, 2009
  • 56. User-Defined Functions (defun verbose-anim ((anim string)) [print-string "Starting " anim] [animate "self" anim] ) • Script functions can be defined and called by script programmer (define-state-script ("kickable-gate") (state ("locked") (on (begin) [verbose-anim "locked-idle"] ) ) ... ) Game
Developers
Conference
2009 26Monday, April 6, 2009
  • 57. The “Self” Argument • Any command operating on a game object takes its unique id (UID) as its first argument • Magic UID "self" refers to the object to which script is attached gate‐17 Game
 Object State
Script
1 Game
Developers
Conference
2009 27Monday, April 6, 2009
  • 58. The “Self” Argument • Any command operating on a game object takes its unique id (UID) as its first argument • Magic UID "self" refers to the object to which script is attached (on (begin) gate‐17 [animate "self" "locked-idle"] Game
 ) Object State
Script
1 self Game
Developers
Conference
2009 27Monday, April 6, 2009
  • 59. The “Self” Argument • Any command operating on a game object takes its unique id (UID) as its first argument • Magic UID "self" refers to the object to which script is attached gate‐17 (on (begin) Game
 [animate "gate-17" "locked-idle"] Object ) State
Script
1 Game
Developers
Conference
2009 27Monday, April 6, 2009
  • 60. The “Self” Argument • Any command operating on a game object takes its unique id (UID) as its first argument • Magic UID "self" refers to the object to which script is attached gate‐17 (on (begin) Game
 [animate "lock-6" "fall-off"] Object ) State
Script
1 lock‐6 Game
 Object Game
Developers
Conference
2009 27Monday, April 6, 2009
  • 61. Changing States (define-state-script ("kickable-gate") (state ("locked") • Transitions to other states via ... (go "state-name") command (on (event "kicked") [when [lock-broken?] • State transitions cause current ] [go "opening"] state’s (on ...) blocks to be ) ) aborted (state ("opening") (on (begin) • Use (on (exit) ...) block for ... clean-up ) ... ) ) Game
Developers
Conference
2009 28Monday, April 6, 2009
  • 62. Changing States (define-state-script ("kickable-gate") (state ("locked") • Transitions to other states via ... (go "state-name") command (on (event "kicked") [when [lock-broken?] • State transitions cause current ] [go "opening"] state’s (on ...) blocks to be ) ) aborted (state ("opening") (on (begin) • Use (on (exit) ...) block for ... clean-up ) ... ) ) Game
Developers
Conference
2009 28Monday, April 6, 2009
  • 63. Changing States (define-state-script ("kickable-gate") (state ("locked") • Transitions to other states via ... (go "state-name") command (on (event "kicked") [when [lock-broken?] • State transitions cause current ] [go "opening"] state’s (on ...) blocks to be ) ) aborted (state ("opening") (on (begin) • Use (on (exit) ...) block for ... clean-up ) ... ) ) Game
Developers
Conference
2009 28Monday, April 6, 2009
  • 64. Tracks • (on ...) blocks contain one or more tracks • A track is a bit like a thread or fiber • Tracks can be put to sleep  Wait for duration • e.g., wait 5 seconds, • wait until frame 23, ...  Wait for an action to be done • duration-agnostic • Tracks can be synchronized via signals Game
Developers
Conference
2009 29Monday, April 6, 2009
  • 65. Tracks (state ("shake-hands") State
"shake‐hands" (on (begin) On
Begin (track ("player")) [wait-move-to "player" "waypoint7"] Track Track P S [signal "player-at-waypoint"] [wait-for-signal "sully-at-waypoint"] [wait-animate "player" "shake-sullys-hand"] s‐a‐w ) (track ("sullivan")) [wait-move-to "sullivan" "waypoint7"] [signal "sully-at-waypoint"] p‐a‐w [wait-for-signal "player-at-waypoint"] [wait-animate "sullivan" "shake-drakes-hand"] ) ) ) Game
Developers
Conference
2009 30Monday, April 6, 2009
  • 66. Tracks (state ("shake-hands") State
"shake‐hands" (on (begin) On
Begin (track ("player")) [wait-move-to "player" "waypoint7"] Track Track P S [signal "player-at-waypoint"] [wait-for-signal "sully-at-waypoint"] [wait-animate "player" "shake-sullys-hand"] s‐a‐w ) (track ("sullivan")) [wait-move-to "sullivan" "waypoint7"] [signal "sully-at-waypoint"] p‐a‐w [wait-for-signal "player-at-waypoint"] [wait-animate "sullivan" "shake-drakes-hand"] ) ) ) Game
Developers
Conference
2009 30Monday, April 6, 2009
  • 67. Tracks (state ("shake-hands") State
"shake‐hands" (on (begin) On
Begin (track ("player")) [wait-move-to "player" "waypoint7"] Track Track P S [signal "player-at-waypoint"] [wait-for-signal "sully-at-waypoint"] [wait-animate "player" "shake-sullys-hand"] s‐a‐w ) (track ("sullivan")) [wait-move-to "sullivan" "waypoint7"] [signal "sully-at-waypoint"] p‐a‐w [wait-for-signal "player-at-waypoint"] [wait-animate "sullivan" "shake-drakes-hand"] ) ) ) Game
Developers
Conference
2009 30Monday, April 6, 2009
  • 68. Tracks (state ("shake-hands") State
"shake‐hands" (on (begin) On
Begin (track ("player")) [wait-move-to "player" "waypoint7"] Track Track P S [signal "player-at-waypoint"] [wait-for-signal "sully-at-waypoint"] [wait-animate "player" "shake-sullys-hand"] s‐a‐w ) (track ("sullivan")) [wait-move-to "sullivan" "waypoint7"] [signal "sully-at-waypoint"] p‐a‐w [wait-for-signal "player-at-waypoint"] [wait-animate "sullivan" "shake-drakes-hand"] ) ) ) Game
Developers
Conference
2009 30Monday, April 6, 2009
  • 69. Tracks (state ("shake-hands") State
"shake‐hands" (on (begin) On
Begin (track ("player")) [wait-move-to "player" "waypoint7"] Track Track P S [signal "player-at-waypoint"] [wait-for-signal "sully-at-waypoint"] [wait-animate "player" "shake-sullys-hand"] p‐a‐w ) (track ("sullivan")) [wait-move-to "sullivan" "waypoint7"] [signal "sully-at-waypoint"] s‐a‐w [wait-for-signal "player-at-waypoint"] [wait-animate "sullivan" "shake-drakes-hand"] ) ) ) Game
Developers
Conference
2009 30Monday, April 6, 2009
  • 70. Track Execution Over Time • Rules for execution of code within a track:  Greedily consume instructions sequentially...  ... until a [wait* ...] command encountered...  ... then relinquish control until the action is complete • NOTE: A [wait* ...] command doesn’t have to wait; for example:  [wait-seconds 0]  [wait-npc-move-to "pos-4"] when she’s already there Game
Developers
Conference
2009 31Monday, April 6, 2009
  • 71. Options and Variable Declarations • Options declared at top of (define-state-script ("kickable-gate") script: :initial-state "closed" :declarations (decl-list  initial state (var "num-attempts" :type int32) (var "is-locked" :type boolean :default #t)  variable declarations )  debugging options (state ("kicked") ... ) ... ) Game
Developers
Conference
2009 32Monday, April 6, 2009
  • 72. Options and Variable Declarations • Options declared at top of (define-state-script ("kickable-gate") script: :initial-state "closed" :declarations (decl-list  initial state (var "num-attempts" :type int32) (var "is-locked" :type boolean :default #t)  variable declarations )  debugging options (state ("kicked") ... ) ... ) Game
Developers
Conference
2009 32Monday, April 6, 2009
  • 73. Options and Variable Declarations • Options declared at top of (define-state-script ("kickable-gate") script: :initial-state "closed" :declarations (decl-list  initial state (var "num-attempts" :type int32) (var "is-locked" :type boolean :default #t)  variable declarations )  debugging options (state ("kicked") ... ) ... ) Game
Developers
Conference
2009 32Monday, April 6, 2009
  • 74. (define-state-script ("kickable-gate") :initial-state "closed" Manipulating Variables :declarations (decl-list (var "num-attempts" :type int32) • Simple commands for reading (var "is-locked" :type boolean :default #t) ) and writing variables (state ("kicked") (on (begin) • Lisp/Scheme uses prefix notation [when [get-boolean "is-locked"] [set-int32 "num-attempts" (a.k.a. Polish notation) [+ 1 [get-int32 "num-attempts"]] ]  [+ a b] calculates (a + b) [wait-animate "self" "kick-failure"] [go "closed"]  [set "x" [+ 1 [get "x"]]] ] increments variable “x” ;; else... [wait-animate "self" "kick-success"] [go "open"] ) ) ... Game
Developers
Conference
2009 33Monday, April 6, 2009
  • 75. (define-state-script ("kickable-gate") :initial-state "closed" Manipulating Variables :declarations (decl-list (var "num-attempts" :type int32) • Simple commands for reading (var "is-locked" :type boolean :default #t) ) and writing variables (state ("kicked") (on (begin) • Lisp/Scheme uses prefix notation [when [get-boolean "is-locked"] [set-int32 "num-attempts" (a.k.a. Polish notation) [+ 1 [get-int32 "num-attempts"]] ]  [+ a b] calculates (a + b) [wait-animate "self" "kick-failure"] [go "closed"]  [set "x" [+ 1 [get "x"]]] ] increments variable “x” ;; else... [wait-animate "self" "kick-success"] [go "open"] ) ) ... Game
Developers
Conference
2009 33Monday, April 6, 2009
  • 76. (define-state-script ("kickable-gate") :initial-state "closed" Manipulating Variables :declarations (decl-list (var "num-attempts" :type int32) • Simple commands for reading (var "is-locked" :type boolean :default #t) ) and writing variables (state ("kicked") (on (begin) • Lisp/Scheme uses prefix notation [when [get-boolean "is-locked"] [set-int32 "num-attempts" (a.k.a. Polish notation) [+ 1 [get-int32 "num-attempts"]] ]  [+ a b] calculates (a + b) [wait-animate "self" "kick-failure"] [go "closed"]  [set "x" [+ 1 [get "x"]]] ] increments variable “x” ;; else... [wait-animate "self" "kick-success"] [go "open"] ) ) ... Game
Developers
Conference
2009 33Monday, April 6, 2009
  • 77. (define-state-script ("kickable-gate") :initial-state "closed" Manipulating Variables :declarations (decl-list (var "num-attempts" :type int32) • Simple commands for reading (var "is-locked" :type boolean :default #t) ) and writing variables (state ("kicked") (on (begin) • Lisp/Scheme uses prefix notation [when [get-boolean "is-locked"] [set-int32 "num-attempts" (a.k.a. Polish notation) [+ 1 [get-int32 "num-attempts"]] ˘ ]  [+ a b] calculates (a + b) [wait-animate "self" "kick-failure"] [go "closed"]  [set "x" [+ 1 [get "x"]]] ] increments variable “x” ;; else... [wait-animate "self" "kick-success"] [go "open"] ) ) ... Game
Developers
Conference
2009 33Monday, April 6, 2009
  • 78. (define-state-script ("kickable-gate") :initial-state "closed" Manipulating Variables :declarations (decl-list (var "num-attempts" :type int32) • Simple commands for reading (var "is-locked" :type boolean :default #t) ) and writing variables (state ("kicked") (on (begin) • Lisp/Scheme uses prefix notation [when [get-boolean "is-locked"] [set-int32 "num-attempts" (a.k.a. Polish notation) [+ 1 [get-int32 "num-attempts"]] ]  [+ a b] calculates (a + b) [wait-animate "self" "kick-failure"] [go "closed"]  [set "x" [+ 1 [get "x"]]] ] increments variable “x” ;; else... [wait-animate "self" "kick-success"] [go "open"] ) ) ... Game
Developers
Conference
2009 33Monday, April 6, 2009
  • 79. Configuration Parameters • All game objects have properties (key-value pairs)  Property values edited in Charter Game
Developers
Conference
2009 34Monday, April 6, 2009
  • 80. Configuration Parameters • All game objects have properties (key-value pairs)  Property values edited in Charter Game
Developers
Conference
2009 34Monday, April 6, 2009
  • 81. Configuration Parameters • Designers can create their own free-form properties, called tags meaning-of-life = 42  Simply type “key = value” in Tags field Game
Developers
Conference
2009 34Monday, April 6, 2009
  • 82. Configuration Parameters • State scripts have read-only access to game object properties...  ... and free-form tags Game
Developers
Conference
2009 35Monday, April 6, 2009
  • 83. Configuration Parameters • State scripts have read-only access to game object properties...  ... and free-form tags (define-state-script ("kickable-gate") (state ("kicked") (on (begin) [wait-animate "self" [tag-string "kick-anim"] ] ) ... ) Game
Developers
Conference
2009 35Monday, April 6, 2009
  • 84. Configuration Parameters • State scripts have read-only access to game object properties...  ... and free-form tags (define-state-script ("kickable-gate") (state ("kicked") (on (begin) [wait-animate "self" [tag-string "kick-anim"] ] ) ... ) Game
Developers
Conference
2009 35Monday, April 6, 2009
  • 85. Configuration Parameters • State scripts have read-only access to game object properties...  ... and free-form tags (define-state-script ("kickable-gate") (state ("kicked") (on (begin) [wait-animate "self" [tag-string "kick-anim"] ] ) ... ) Game
Developers
Conference
2009 35Monday, April 6, 2009
  • 86. Data Definition and Runtime (define-state-script ("kickable-gate") • Offline data-definition language (state ("locked") (on (begin) (Scheme) is intermingled with [print-string "Starting idle!"] [animate "self" "locked-idle"] runtime code ) (on (event "kicked") [when [lock-broken?] [print-string "BAM!"] ] [if [task-complete? "wave2"] [print-string "Complete!"] [print-string "NOT!!!"] ] ) ) ... ) Game
Developers
Conference
2009 36Monday, April 6, 2009
  • 87. Data Definition and Runtime (define-state-script ("kickable-gate") • Offline data-definition language (state ("locked") (on (begin) (Scheme) is intermingled with [print-string "Starting idle!"] [animate "self" "locked-idle"] runtime code ) (on (event "kicked") [when [lock-broken?] [print-string "BAM!"] ] [if [task-complete? "wave2"] [print-string "Complete!"] [print-string "NOT!!!"] ] ) ) ... ) Game
Developers
Conference
2009 36Monday, April 6, 2009
  • 88. Data Definition and Runtime class Vector3 { private: float x, y, z; • Really no different than the public: float Dot(const Vector3& b) distinction between declarations { return (x * b.x and definitions in C++ + y * b.y + z * b.z); } ... }; Game
Developers
Conference
2009 36Monday, April 6, 2009
  • 89. Data Definition and Runtime class Vector3 { private: float x, y, z; • Really no different than the public: float Dot(const Vector3& b) distinction between declarations { return (x * b.x and definitions in C++ + y * b.y + z * b.z); } ... }; Game
Developers
Conference
2009 36Monday, April 6, 2009
  • 90. Case Studies 37Monday, April 6, 2009
  • 91. Custom Object Type: Breakable Sign Game
Developers
Conference
2009 38Monday, April 6, 2009
  • 92. Custom Object Type: Breakable Sign Game
Developers
Conference
2009 38Monday, April 6, 2009
  • 93. Custom Object Type: Breakable Sign (define-state-script ("falling-sign") (state ("untouched") (on (update) [when [task-complete? "wz-post-combat"] [go "fallen"] ] ) (on (event "hanging-from") [go "breaking"] ) ) ... Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 94. Custom Object Type: Breakable Sign (define-state-script ("falling-sign") (state ("untouched") (on (update) [when [task-complete? "wz-post-combat"] [go "fallen"] ] ) (on (event "hanging-from") [go "breaking"] ) ) ... Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 95. Custom Object Type: Breakable Sign (define-state-script ("falling-sign") (state ("untouched") (on (update) [when [task-complete? "wz-post-combat"] [go "fallen"] ] ) (on (event "hanging-from") [go "breaking"] ) ) ... Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 96. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 97. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 98. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 99. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 100. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 101. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 102. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 103. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 104. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) [spawn-particles-at-joint "self" "hinge" "sign-break-dust"] [wait-animate "self" "sign-break"] [go "fallen"] ) ) (state ("fallen") (on (begin) [animate "self" "sign-broken"] ;; looping ) ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 105. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) (define-state-script ("falling-sign") [spawn-particles-at-joint "self" (state ("untouched") "hinge" (on (update) "sign-break-dust"] [when [task-complete? "wz-post-combat"] [wait-animate "self" "sign-break"] [go "fallen"] [go "fallen"] ] ) ) ) (on (event "hanging-from") (state ("fallen") [go "breaking"] (on (begin) ) [animate "self" "sign-broken"] ;; looping ) ) ... ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 106. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) (define-state-script ("falling-sign") [spawn-particles-at-joint "self" (state ("untouched") "hinge" (on (update) "sign-break-dust"] [when [task-complete? "wz-post-combat"] [wait-animate "self" "sign-break"] [go "fallen"] [go "fallen"] ] ) ) ) (on (event "hanging-from") (state ("fallen") [go "breaking"] (on (begin) ) [animate "self" "sign-broken"] ;; looping ) ) ... ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 107. Custom Object Type: Breakable Sign (state ("breaking") (on (begin) (define-state-script ("falling-sign") [spawn-particles-at-joint "self" (state ("untouched") "hinge" (on (update) "sign-break-dust"] [when [task-complete? "wz-post-combat"] [wait-animate "self" "sign-break"] [go "fallen"] [go "fallen"] ] ) ) ) (on (event "hanging-from") (state ("fallen") [go "breaking"] (on (begin) ) [animate "self" "sign-broken"] ;; looping ) ) ... ) ) Game
Developers
Conference
2009 39Monday, April 6, 2009
  • 108. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 109. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 110. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 111. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 112. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 113. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 114. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 115. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 116. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 117. Making the Sign Script Generic (state ("animating") (on (begin) [spawn-particles-at-joint "self" (define-state-script ("simple-animating-obj") [tag-string "particle-joint"] (state ("initial") [tag-string "particle-name"]] (on (update) [wait-animate "self" [when [task-complete? [tag-string "anim-name"]] [tag-string "done-task"]] [go "done"] [go "done"] ) ] ) ) (state ("done") (on (event "hanging-from") (on (begin) [go "animating"] [animate "self" ) [tag-string "done-anim-name"]] ) ) ... ) ) Game
Developers
Conference
2009 40Monday, April 6, 2009
  • 118. In-Game Debugging Game
Developers
Conference
2009 41Monday, April 6, 2009
  • 119. In-Game Debugging Game
Developers
Conference
2009 41Monday, April 6, 2009
  • 120. In-Game Debugging Game
Developers
Conference
2009 41Monday, April 6, 2009
  • 121. In-Game Debugging Game
Developers
Conference
2009 41Monday, April 6, 2009
  • 122. In-Game Debugging Game
Developers
Conference
2009 41Monday, April 6, 2009
  • 123. In-Game Debugging Game
Developers
Conference
2009 41Monday, April 6, 2009
  • 124. In-Game Cinematic: Bus Crash Game
Developers
Conference
2009 42Monday, April 6, 2009
  • 125. In-Game Cinematic: Bus Crash (state ("crash") (on (begin) (define-state-script ("wz-bus-crash") (state ("spawn-soldiers") (track ("bus") (on (begin) [wait-animate "bus-1" "bus-crash" [get-locator "ref-bus-crash-1"]] [player-disable-controls [signal "bus-done"] (controls all-but-right-stick)] [spawn-npc-in-combat "npc-wz-52"] ) [spawn-npc-in-combat "npc-wz-53"] (track ("player") ... [animate "player" "player-watch-crash" [go "crash"] [get-locator "ref-bus-crash-1"]] [wait-until-frame 250] ) ) [say "player" "vox-wz-drk-01-what-the"] ... [signal "drake-done"] ) ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 126. In-Game Cinematic: Bus Crash (state ("crash") (on (begin) (define-state-script ("wz-bus-crash") (state ("spawn-soldiers") (track ("bus") (on (begin) [wait-animate "bus-1" "bus-crash" [get-locator "ref-bus-crash-1"]] [player-disable-controls [signal "bus-done"] (controls all-but-right-stick)] [spawn-npc-in-combat "npc-wz-52"] ) [spawn-npc-in-combat "npc-wz-53"] (track ("player") ... [animate "player" "player-watch-crash" [go "crash"] [get-locator "ref-bus-crash-1"]] [wait-until-frame 250] ) ) [say "player" "vox-wz-drk-01-what-the"] ... [signal "drake-done"] ) ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 127. In-Game Cinematic: Bus Crash (state ("crash") (on (begin) (define-state-script ("wz-bus-crash") (state ("spawn-soldiers") (track ("bus") (on (begin) [wait-animate "bus-1" "bus-crash" [get-locator "ref-bus-crash-1"]] [player-disable-controls [signal "bus-done"] (controls all-but-right-stick)] [spawn-npc-in-combat "npc-wz-52"] ) [spawn-npc-in-combat "npc-wz-53"] (track ("player") ... [animate "player" "player-watch-crash" [go "crash"] [get-locator "ref-bus-crash-1"]] [wait-until-frame 250] ) ) [say "player" "vox-wz-drk-01-what-the"] ... [signal "drake-done"] ) ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 128. In-Game Cinematic: Bus Crash (state ("crash") (on (begin) (define-state-script ("wz-bus-crash") (state ("spawn-soldiers") (track ("bus") (on (begin) [wait-animate "bus-1" "bus-crash" [get-locator "ref-bus-crash-1"]] [player-disable-controls [signal "bus-done"] (controls all-but-right-stick)] [spawn-npc-in-combat "npc-wz-52"] ) [spawn-npc-in-combat "npc-wz-53"] (track ("player") ... [animate "player" "player-watch-crash" [go "crash"] [get-locator "ref-bus-crash-1"]] [wait-until-frame 250] ) ) [say "player" "vox-wz-drk-01-what-the"] ... [signal "drake-done"] ) ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 129. In-Game Cinematic: Bus Crash (state ("crash") (on (begin) (define-state-script ("wz-bus-crash") (state ("spawn-soldiers") (track ("bus") (on (begin) [wait-animate "bus-1" "bus-crash" [get-locator "ref-bus-crash-1"]] [player-disable-controls [signal "bus-done"] (controls all-but-right-stick)] [spawn-npc-in-combat "npc-wz-52"] ) [spawn-npc-in-combat "npc-wz-53"] (track ("player") ... [animate "player" "player-watch-crash" [go "crash"] [get-locator "ref-bus-crash-1"]] [wait-until-frame 250] ) ) [say "player" "vox-wz-drk-01-what-the"] ... [signal "drake-done"] ) ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 130. In-Game Cinematic: Bus Crash (state ("crash") (on (begin) (define-state-script ("wz-bus-crash") (state ("spawn-soldiers") (track ("bus") (on (begin) [wait-animate "bus-1" "bus-crash" [get-locator "ref-bus-crash-1"]] [player-disable-controls [signal "bus-done"] (controls all-but-right-stick)] [spawn-npc-in-combat "npc-wz-52"] ) [spawn-npc-in-combat "npc-wz-53"] (track ("player") ... [animate "player" "player-watch-crash" [go "crash"] [get-locator "ref-bus-crash-1"]] [wait-until-frame 250] ) ) [say "player" "vox-wz-drk-01-what-the"] ... [signal "drake-done"] ) ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 131. In-Game Cinematic: Bus Crash (state ("crash") (on (begin) (define-state-script ("wz-bus-crash") (state ("spawn-soldiers") (track ("bus") (on (begin) [wait-animate "bus-1" "bus-crash" [get-locator "ref-bus-crash-1"]] [player-disable-controls [signal "bus-done"] (controls all-but-right-stick)] [spawn-npc-in-combat "npc-wz-52"] ) [spawn-npc-in-combat "npc-wz-53"] (track ("player") ... [animate "player" "player-watch-crash" [go "crash"] [get-locator "ref-bus-crash-1"]] [wait-until-frame 250] ) ) [say "player" "vox-wz-drk-01-what-the"] ... [signal "drake-done"] ) ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 132. In-Game Cinematic: Bus Crash (state ("crash") ... (track ("guy-hit-by-bus") (define-state-script ("wz-bus-crash") [wait-animate "npc-wz-52" "npc-hit-by-bus" (state ("spawn-soldiers") [get-locator "ref-bus-crash-1"]] (on (begin) [npc-die "npc-wz-52"] [player-disable-controls [signal "npc-dead"] (controls all-but-right-stick)] ) [spawn-npc-in-combat "npc-wz-52"] (track ("wait-for-all-done") [spawn-npc-in-combat "npc-wz-53"] [wait-for-signal "bus-done"] ... [wait-for-signal "drake-done"] [go "crash"] [wait-for-signal "npc-dead"] ) [go "done"] ) ) ... ) ) (state ("done") ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 133. In-Game Cinematic: Bus Crash (state ("crash") ... (track ("guy-hit-by-bus") (define-state-script ("wz-bus-crash") [wait-animate "npc-wz-52" "npc-hit-by-bus" (state ("spawn-soldiers") [get-locator "ref-bus-crash-1"]] (on (begin) [npc-die "npc-wz-52"] [player-disable-controls [signal "npc-dead"] (controls all-but-right-stick)] ) [spawn-npc-in-combat "npc-wz-52"] (track ("wait-for-all-done") [spawn-npc-in-combat "npc-wz-53"] [wait-for-signal "bus-done"] ... [wait-for-signal "drake-done"] [go "crash"] [wait-for-signal "npc-dead"] ) [go "done"] ) ) ... ) ) (state ("done") ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 134. In-Game Cinematic: Bus Crash (state ("crash") ... (track ("guy-hit-by-bus") (define-state-script ("wz-bus-crash") [wait-animate "npc-wz-52" "npc-hit-by-bus" (state ("spawn-soldiers") [get-locator "ref-bus-crash-1"]] (on (begin) [npc-die "npc-wz-52"] [player-disable-controls [signal "npc-dead"] (controls all-but-right-stick)] ) [spawn-npc-in-combat "npc-wz-52"] (track ("wait-for-all-done") [spawn-npc-in-combat "npc-wz-53"] [wait-for-signal "bus-done"] ... [wait-for-signal "drake-done"] [go "crash"] [wait-for-signal "npc-dead"] ) [go "done"] ) ) ... ) ) (state ("done") ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 135. In-Game Cinematic: Bus Crash (state ("crash") ... (track ("guy-hit-by-bus") (define-state-script ("wz-bus-crash") [wait-animate "npc-wz-52" "npc-hit-by-bus" (state ("spawn-soldiers") [get-locator "ref-bus-crash-1"]] (on (begin) [npc-die "npc-wz-52"] [player-disable-controls [signal "npc-dead"] (controls all-but-right-stick)] ) [spawn-npc-in-combat "npc-wz-52"] (track ("wait-for-all-done") [spawn-npc-in-combat "npc-wz-53"] [wait-for-signal "bus-done"] ... [wait-for-signal "drake-done"] [go "crash"] [wait-for-signal "npc-dead"] ) [go "done"] ) ) ... ) ) (state ("done") ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 136. In-Game Cinematic: Bus Crash (state ("crash") ... (track ("guy-hit-by-bus") (define-state-script ("wz-bus-crash") [wait-animate "npc-wz-52" "npc-hit-by-bus" (state ("spawn-soldiers") [get-locator "ref-bus-crash-1"]] (on (begin) [npc-die "npc-wz-52"] [player-disable-controls [signal "npc-dead"] (controls all-but-right-stick)] ) [spawn-npc-in-combat "npc-wz-52"] (track ("wait-for-all-done") [spawn-npc-in-combat "npc-wz-53"] [wait-for-signal "bus-done"] ... [wait-for-signal "drake-done"] [go "crash"] [wait-for-signal "npc-dead"] ) [go "done"] ) ) ... ) ) (state ("done") ... Game
Developers
Conference
2009 43Monday, April 6, 2009
  • 137. Implementation 44Monday, April 6, 2009
  • 138. Virtual Machine • Scheme-like runtime language implemented by a simple VM  Each track compiled into block of byte code called a lambda (define-state-script ("kickable-gate") (state ("locked") (on (begin) (track ("gate") ... ) (track ("lock") ... ) ) ) ) Game
Developers
Conference
2009 45Monday, April 6, 2009
  • 139. Virtual Machine • Scheme-like runtime language implemented by a simple VM  Each track compiled into block of byte code called a lambda (define-state-script ("kickable-gate") (state ("locked") opcode1
operand1
operand2 (on (begin) 


opcode2 (track ("gate") 


opcode3
operand3 ... ) (track ("lock") ... ) ) ) ) Game
Developers
Conference
2009 45Monday, April 6, 2009
  • 140. Virtual Machine • Scheme-like runtime language implemented by a simple VM  Each track compiled into block of byte code called a lambda (define-state-script ("kickable-gate") (state ("locked") opcode1
operand1
operand2 (on (begin) 


opcode2 (track ("gate") 


opcode3
operand3 ... ) (track ("lock") opcode4
operand4 ... 


opcode5
operand5 ) 


opcode6 ) ) ) Game
Developers
Conference
2009 45Monday, April 6, 2009
  • 141. Virtual Machine • Internal state of VM consists of:  Pointer to current lambda (byte code program) cur
instr lambda  Index to current instruction reg0 reg2 ___ ___  Bank of registers for temporary reg1 reg4 ___ and immediate data • Registers are of type variant Game
Developers
Conference
2009 46Monday, April 6, 2009
  • 142. Virtual Machine • Internal state of VM consists of:  Pointer to current lambda (byte code program) cur
instr lambda  Index to current instruction reg0 reg2 ___ ___  Bank of registers for temporary reg1 reg4 ___ and immediate data • Registers are of type variant Game
Developers
Conference
2009 46Monday, April 6, 2009
  • 143. Virtual Machine • Internal state of VM consists of:  Pointer to current lambda (byte code program) cur
instr lambda  Index to current instruction reg0 reg2 ___ ___  Bank of registers for temporary reg1 reg4 ___ and immediate data • Registers are of type variant Game
Developers
Conference
2009 46Monday, April 6, 2009
  • 144. Virtual Machine • Language supports nested lambda ___ function calls ___ ___ • Hence requires call stack ___  Stack frame = bank of registers + program counter cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 47Monday, April 6, 2009
  • 145. Virtual Machine • Language supports nested lambda ___ function calls ___ ___ • Hence requires call stack ___  Stack frame = bank of cur
instr registers + program counter reg0 reg2 reg1 reg4 cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 47Monday, April 6, 2009
  • 146. Virtual Machine • Language supports nested cur
instr lambda reg0 reg2 ___ function calls ___ reg1 reg4 ___ • Hence requires call stack ___  Stack frame = bank of cur
instr registers + program counter reg0 reg2 reg1 reg4 cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 47Monday, April 6, 2009
  • 147. Virtual Machine • Language supports nested lambda ___ function calls ___ ___ • Hence requires call stack ___  Stack frame = bank of cur
instr registers + program counter reg0 reg2 reg1 reg4 cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 47Monday, April 6, 2009
  • 148. Continuations • State script code can wait (sleep) lambda ___ • Implemented via something ___ ___ known as a continuation ___ cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 48Monday, April 6, 2009
  • 149. Continuations • State script code can wait (sleep) lambda ___ • Implemented via something ___ ___ known as a continuation ___ cur
instr reg0 reg2 reg1 reg4 cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 48Monday, April 6, 2009
  • 150. Continuations • State script code can wait (sleep) lambda ___ • Implemented via something ___ ___ known as a continuation ___ conOnuaOon Game
Developers
Conference
2009 48Monday, April 6, 2009
  • 151. Continuations • State script code can wait (sleep) lambda ___ • Implemented via something ___ ___ known as a continuation ___ cur
instr reg0 reg2 reg1 reg4 cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 48Monday, April 6, 2009
  • 152. Continuations • State script code can wait (sleep) cur
instr lambda reg0 reg2 ___ • Implemented via something ___ reg1 reg4 ___ known as a continuation ___ cur
instr reg0 reg2 reg1 reg4 cur
instr reg0 reg2 reg1 reg4 Game
Developers
Conference
2009 48Monday, April 6, 2009
  • 153. Native C++ Functions • The “meat” of an (on ...) block is its command sequence  Some commands are user-defined: (defun func1 (...))  Most commands are C++ hooks into the engine • Simple hash table maps function names to C++ code (define-c-function wait-animate Variant ScriptWaitAnimate(int argc, Variant* argv) (object-name string) { (anim-name string) ... ) } Game
Developers
Conference
2009 49Monday, April 6, 2009
  • 154. Variant ScriptWaitAnimate(int argc, Variant* argv) { StringId objName = SC_ARG(0, StringId, NULL); StringId animName = SC_ARG(1, StringId, NULL); if (!objName) return ScriptError("wait-animate: expected object name (arg1)n"); if (!animName) return ScriptError("wait-animate: expected animation name (arg2)n"); // find the object ProcessGameObject* pObj = g_processMgr.Lookup(objName); if (!pObj) return ScriptError("wait-animate: could not find %sn", StringIdToString(objName)); // instruct object to play animation, and wake up this script when done pObj->WaitAnimate(animName, g_scriptContext); g_scriptContext.Suspend(); // go to sleep until anim is done return Variant(true); } Game
Developers
Conference
2009 50Monday, April 6, 2009
  • 155. Game
Developers
Conference
2009 51Monday, April 6, 2009
  • 156. Conclusion 52Monday, April 6, 2009
  • 157. Key Features • Key features of a successful scripting system:  Virtual machine integrated into game engine  Ability to run code every frame (update)  Ability to respond to events, and send events  Ability to reference game objects (by handle, unique id, etc.)  Ability to manipulate game objects  Designers can define new object types in script Game
Developers
Conference
2009 53Monday, April 6, 2009
  • 158. Architectural Styles • Many different engine-script architectures:  script drives engine (engine just a library called by script)  engine drives script... • simple scripted event handlers • scripted properties or components • scripted game object classes Game
Developers
Conference
2009 54Monday, April 6, 2009
  • 159. Some Advice... • Good debugging tools are crucial  Understandable error messages from compiler  In-game display of running scripts, or some kind of debugger  Simple logging to TTY/console (e.g. [print-string "message"]) • Watch for race conditions  Event arrives too early or too late—missed  Object you’re trying to control hasn’t spawned yet, or has died  Tracks not synchronized properly Game
Developers
Conference
2009 55Monday, April 6, 2009
  • 160. With Great Power... • ... comes great responsibility • Your designers can now:  break the build  introduce progression stoppers  crash the game • Take the leap of faith, but...  PLAN FOR IT! Game
Developers
Conference
2009 56Monday, April 6, 2009
  • 161. With Great Power... • ... comes great responsibility • Your designers can now:  break the build  introduce progression stoppers  crash the game • Take the leap of faith, but...  PLAN FOR IT! Game
Developers
Conference
2009 56Monday, April 6, 2009
  • 162. Thanks For Listening! • Free free to send questions to me at: jason_gregory@naughtydog.com • Naughty Dog is hiring! Send resumes to Candace Walker at: candace_walker@naughtydog.com Game
Developers
Conference
2009 57Monday, April 6, 2009