DOC PREVIEW
U-M CIS 487 - Torque Script

This preview shows page 1-2-3-4-30-31-32-33-34-62-63-64-65 out of 65 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Torque ScriptScripting AdvantagesNecessary FeaturesUsing the ConsoleSyntaxTorque FeaturesVariablesBasic Data TypesTagged StringsString OperationsString Escape SequencesArraysVectorsOperatorsif-then-elseswitchforwhileFunctions - 1Functions - 2Functions - 3Objects - 1Objects - 2Object - 3Object - 4Object - 5Object - 6Object - 7Using ObjectsDynamic Fields - 1Dynamic Fields - 2Console Functions - 1Console Functions - 2Console Functions - 3Packages - 1Packages - 2Packages - 3Engine-Console Interface - 1Engine-Console Interface - 2Engine-Console Interface - 3Engine-Console Interface - 4addField( )Slide 43addFieldV( )Macros -1Macros - 2removeField( )Con::addVariableConsoleMethod - 1ConsoleMethod - 2ConsoleMethod - 3ConsoleFunction - 1ConsoleFunction - 2Con::getLocalVariable( )Con::setLocalVariable()Console Printing FunctionsDatablocks - 1Datablocks - 2Creating Datablock Objects - 1Creating Datablock Objects - 2Declaring Datablocks - 1Declaring Datablocks - 2NamespacesObject Namespace - 1Object Namespace - 201/14/19 1Torque ScriptCIS 487/587Bruce R. MaximUM-Dearborn01/14/19 2Scripting Advantages•Useful for prototyping without recompilation•Makes debugging easier•Allows for game customization and tweaking•Allows players to make their own total-mod based on an existing game structure•Any functional component that is not time critical can be written using scripting language rather than a compiled language01/14/19 3Necessary Features•Basic programming language features (variables, data types, control structures)•Access to engine-structures (rendering, audio, physics, AI, I/O, object management)•Familiar and consistent syntax•Object functionality (encapsulation, inheritance, polymorphism)•Dynamic scoping and memory management•Compilation of virtual machine “p-code”01/14/19 4Using the Console•Single script statements can typed in the console command line or an entire script can loaded from a file•The console window is opened by typing “~” once a Torque application is running•Ctrl-V allows pasting from clipboard into command line•The echo command can be used –echo(“Torque rocks”);–echo(1+1);01/14/19 5Syntax•Torque is type insensitive–“1.2” == 1.2•Torque is case insensitive–$a == $A•The “;” is used as a statement terminator–$a = “a text string”;01/14/19 6Torque Features•Contains C++ arithmetic operators plus a few extra string operators•Control structures and function definition are similar to C++•Provides engine object inheritance and polymorphism•Supports use of Namespaces•On-demand loading and unloading of functions•Compiles and executes pcode01/14/19 7Variables•Variables do not need explicit declaration•Variable names begin with letter and contain any number of letters, digits, or “_”•Local and global variables–%local_var = value;–$global_var = value;01/14/19 8Basic Data Types•Numbers:–123 (Integer) –1.234 (floating point) –1234e-3 (scientific notation) –0xc001 (hexadecimal)•Strings–"abcd" (string) –'abcd' (tagged string) •Booleans–true (1)–false (0)01/14/19 9Tagged Strings•Tagged strings have special numeric data associated with them•Tagged strings are used for sending strings across networks more efficiently•Tagged strings behave like normal strings•Tagged values can only be printed by detagging them after transmission–echo(“detagging example “ detag(‘$b’));01/14/19 10String Operations•Syntax–“string 1” op “string “•Operators–@ (concatenates two strings) –TAB (concatenation with tab) –SPC (concatenation with space) –NL (newline between strings)01/14/19 11String Escape Sequences\n (newline) \r (carriage return) \t (tab) \c0...\c9 (colorize subsequent text – predefined color) \cr (reset to default color) \cp (push current color on color stack) \co (pop color from color stack) \xhh (two digit hex value ASCII code) \\ (backslash)01/14/19 12Arrays•Example–$MyArray[n] (Single-dimension)–$MyMultiArray[m,n] (Multi-dimension)–$MyMultiArray[m_n] (Multi-dimension)•Refernces–$a != $a[0]–$a0 == $a[0]–$b[0,0] == $b0_001/14/19 13Vectors•Allow group of numeric values to be manipulated in sets of 3 or 4•Stored as strings, but interpreted as vectors•Torque provides a set of script operators for vectors •Example–“1.0 1.0 1.0 1.0” (4 element vector)01/14/19 14Operators•Boolean and arithmetic operators similar to those found in C++•The ++ and --operators are used only as postfix operators•The string comparison operators are–$= (test for string equality)–!$= (test for string inequality)01/14/19 15if-then-else•Brackets optional for single line statements•Nested if-then-else statements are allowed •Exampleif(expression) { statements; } else { alternate statements; }01/14/19 16switchswitch(expression){ case value0: statements; break; case value1: statements; break; default: statements; }; •Switch only works for numeric expressions•Use switch$•The breaks are not really needed since Torque only executes one case01/14/19 17for•Examplesfor(expression0; expression1; expression2) { statement(s); }for(%count = 0; %count < 5; %count++) { echo(%count); }01/14/19 18while•Exampleswhile(expression) { statements; } %count = 0; while (%count < 5) { echo(%count); %count++; }01/14/19 19Functions - 1•Functions cannot have multiple prototypes (always keeps the most recently defined)•Torque does support the concept of packages to work around the duplicate name problem•Functions can be recursive•If functions are passed fewer actual parameters than the number the defined, the missing parameters will be assigned null string values01/14/19 20Functions - 2// function declarationfunction echoRepeat (%echoString, %repeatCount) { for (%count = 0; %count < %repeatCount; %count++) { echo(%echoString); } } // function call from console or scriptechoRepeat("hello!", 5);01/14/19 21Functions - 3// recursive functionfunction echoRepeat (%echoString, %repeatCount) { if (%repeatCount > 0) { echo(%echoString); echoRepeat(%echoString, %repeatCount--); } } // calling recursive functionechoRepeat("hello!", 5);01/14/19 22Objects - 1•Every game item is considered an object•Even C++ objects are accessible via scripts•Every game object is assigned a numeric ID known as a handle•An objects may be assigned a


View Full Document

U-M CIS 487 - Torque Script

Documents in this Course
Mad Maxim

Mad Maxim

10 pages

DirectX

DirectX

10 pages

Load more
Download Torque Script
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Torque Script and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Torque Script 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?