Script Language: Conventions: Overview of Script Elements
|
![]() |
The various elements of an AGAST game are variables, strings, constants, objects, scripts, events, and resources. Those elements that are declared in the game script files (script files in the game directory) are available throughout the entire game, while those declared in a scene script file (a script file in one of the scene directories) is only available when the player is in that scene. Variables are values that can be used to store the state of the game, and they can be used in calculations. When the user talks to a character, for example, a variable can be set so that it will be known for future conversations. In addition to game and scene variables, script variables can be declared inside a script that last only the duration of that script’s execution. Constants are like variables, except their value cannot be modified. They exist only for convenience and maintainability. Strings are variable-length arrays of characters. Each string in the game has an index into the string table, which is a positive integer value, and some share the same index if they match exactly. Strings that are declared are guaranteed to have a unique index, even if they match another string. Objects define the user interaction in a scene and represent anything that can move or change, from fully animated and speaking actors to background animation, or are simply regions that can be clicked. Objects can be manipulated by changing their properties, or by calling built-in functions that direct their action. The player himself is typically an object that is declared in a game script file. A script is a sequence of statements (like a function or procedure). It can be started when an event occurs, or it can be called or started by another script. Calling a script causes the caller to wait for it to return, while starting it executed it independently. A script must only execute for one interpreter cycle, and then either return (finish executing) or pass control by delaying for one or more cycles. (This is non-preemptive multithreading, a type of parellel execution that allows the complete control over game scheduling.) Events are used to start scripts when something happens in the game, such as when the user clicks an object on another object, enters a new scene, or starts the game. There are also forms of default events that are triggered when there is no specific event to handle a crazy situation. Such a default event might start a script that directs the player’s character to say something like "I can't do that." Resources, or resource files, are not part of a script file, but are separate binary data files. Resources store graphics and sounds that can be referenced by scripts using identifiers derived from their filenames. The resource’s directory determines whether it is a game or scene resource. The interpreter automatically loads, allocates, and deallocates resources during game execution. In addition to those game elements, there are predefined functions and properties that are used to control the state of the interpreter, and direct the behavior of objects. A property is like a built-in variable that is used to evaluate or assign some property of the interpreter, like the current background image resource or mouse coordinates, or a property of the active object, like its coordinates or text color. A function is like a script that may be passed a list of values via an argument list, and it returns a value. See Also... |
![]() |
![]() ![]() ![]() ![]() ![]() |