Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming.

Similar presentations


Presentation on theme: "Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming."— Presentation transcript:

1 Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming

2 Dr. Ken Hoganson, Kennesaw State University On the CD Torque UltraEdit32 (not required to use) Sound editor: Audacity Shape editor: MilkShape PaintShop Pro (trial version) Building interior creation tool: QuArK Various demos

3 Dr. Ken Hoganson, Kennesaw State University Example Torque Script // ======================================================== // geometry.cs // This program adds calculates the distance around the perimiter of // a quadrilateral, as well as the area of the quadrilateral and outputs the // values. It recognizes whether the quadrilateral is a square or a rectangle // modifies its output accordingly. Program assumes that all angles in the // quadrilateral are equal. Demonstrates the if-else statement. // ========================================================= function calcAndPrint(%theWidth, %theHeight) // ------------------------------------------------------------------------ // This function does the shape analysis and prints the result. // PARAMETERS: %theWidth - horizontal dimension // %theHeight - vertical dimension // RETURNS: none // ------------------------------------------------------------------------

4 Dr. Ken Hoganson, Kennesaw State University Example Torque Script function calcAndPrint(%theWidth, %theHeight) { // calculate perimeter %perimeter = 2 * (%theWidth+%theHeight); // calculate area %area = %theWidth * %theHeight; // first, setup the dimension output string %prompt = "For a " @ %theWidth @ " by " @ %theHeight @ " quadrilateral, area and perimeter of "; // analyze the shape's dimensions and select different // descripters based on the shape's dimensions if (%theWidth == %theHeight) // if true, then it's a square %prompt = %prompt @ "square: "; else // otherwise it's a rectangle %prompt = %prompt @ "rectangle: "; // always output the analysis print (%prompt @ %area @ " " @ %perimeter); }

5 Dr. Ken Hoganson, Kennesaw State University Example Torque Script function main() { // ----------------------------------------------------------------- ------- // Entry point for the program. // ----------------------------------------------------------------- ------- // calculate and output the results for three // known dimension sets calcAndPrint(22, 26); // rectangle calcAndPrint(31, 31); // square calcAndPrint(47, 98); // rectangle }

6 Dr. Ken Hoganson, Kennesaw State University Torque on the Web http://www.garagegames.com/ Claim 25 major games published based on the Torque game engine Resources and etc. Garagegames has an intenational presence, exhibiting at the major game conferences and expos.

7 Dr. Ken Hoganson, Kennesaw State University Modern Paradigm Used to be: interpreted was too slow, all serious programming was with compiled languages Now with faster computers available, we are using hybrid paradigm: ◦ Compiled functions and systems/virtual machines ◦ Program with script/interpreted: high-level, may be easier to work with, is easier to develop custom functionality (like a game engine) ◦ May use intermediate byte-code ◦ I have used this concept in the past to build simulation systems.

8 Dr. Ken Hoganson, Kennesaw State University Variables Differences compared with compiled C/C++ Typeless: variables do not have a type. Think of variable names as pointers to data. The name is just a name, it’s the data that has the type (int, char, float, etc). Variable Declarations: declared on first use. No need to formally declare in advance of use.

9 Dr. Ken Hoganson, Kennesaw State University Hello World // =================================================== ===================== // HelloWorld.cs // // This module is a program that prints a simple greeting on the screen. // // =================================================== ===================== function main() // ---------------------------------------------------- // Entry point for the program. // ---------------------------------------------------- { print("Hello World"); }

10 Dr. Ken Hoganson, Kennesaw State University File extensions Note the extension of.cs for Torque scripts. After “compiling”.cs.dso

11 Dr. Ken Hoganson, Kennesaw State University Expressions Terminate with “;” Use braces for blocks: { } if (%num > 10) { print(“Greater than 10”); } else { print(“Less than 10”); } Statements can span more than one line – goes until “;”

12 Dr. Ken Hoganson, Kennesaw State University keywords break case continue default do else false for function if new return switch true while

13 Dr. Ken Hoganson, Kennesaw State University Variable names Must not be a Torque keyword Must start with a letter May contain only letters, numbers, or underscore NOT case sensitive Choose meaningful names Suggestion: combine uppper/lower and underscore in names: %Round_Door%Rect_Door (may be an emerging soft standard for script writing) Must be preceded by either “$” or “%” (next slide)

14 Dr. Ken Hoganson, Kennesaw State University Scope %,$ used in front of variable name % local variable – accessible only within the local function $ global variable – accessible throughout the entire program

15 Dr. Ken Hoganson, Kennesaw State University Arrays Square brackets [ ] for arrays Index is an integer No need to declare in advance $Apple = 5; $Prices[$Apple] = 0.59; Of course, one of the values in using arrays is the ability to iterate through them, so using value in an array in numeric sequence makes sense. Does not support 2-D arrays

16 Dr. Ken Hoganson, Kennesaw State University Fruitloopy.cs On my install, source for the textbook, after install on my machine, is in a subdirectory call bookcode. I copied fruitloopy.cs to its parent directory (which is c:\3DGPAi1\ch2)

17 Dr. Ken Hoganson, Kennesaw State University fruitloopy.cs / ========================================================== ============== // FruitLoopy.cs // // This module is a program that prints a simple greeting on the screen. // This program adds up the costs and quantities of selected fruit types // and outputs the results to the display. This module is a variation // of the the Fruit.cs module // ========================================================== ============== function main() // ---------------------------------------------------- // Entry point for the program. // ---------------------------------------------------- { // // ----------------- Initialization --------------------- //

18 Dr. Ken Hoganson, Kennesaw State University fruitloopy.cs %numFruitTypes = 5; // so we know how many types are in our arrays %bananaIdx=0; // initilize the values of our index variables %appleIdx=1; %orangeIdx=2; %mangoIdx=3; %pearIdx=4; %names[%bananaIdx] = "bananas"; // initilize the fruit name values %names[%appleIdx] = "apples"; %names[%orangeIdx] = "oranges"; %names[%mangoIdx] = "mangos"; %names[%pearIdx] = "pears"; %cost[%bananaIdx] = 1.15; // initilize the price values %cost[%appleIdx] = 0.55; %cost[%orangeIdx] = 0.55; %cost[%mangoIdx] = 1.90; %cost[%pearIdx] = 0.68; %quantity[%bananaIdx] = 1; // initilize the quantity values %quantity[%appleIdx] = 3; %quantity[%orangeIdx] = 4; %quantity[%mangoIdx] = 1; %quantity[%pearIdx] = 2;

19 Dr. Ken Hoganson, Kennesaw State University fruitloopy.cs %numFruit=0; // always a good idea to initialize *all* variables! %totalCost=0; // (even if we know we are going to change them later) // // ----------------- Computation --------------------- // // Display the known statistics of the fruit collection for (%index = 0; %index < %numFruitTypes; %index++) { print("Cost of " @ %names[%index] @ ":$" @ %cost[%index]); print("Number of " @ %names[%index] @ ":" @ %quantity[%index]); } // count up all the pieces of fruit, and display that result for (%index = 0; %index <= %numFruitTypes; %index++) { %numFruit = %numFruit + %quantity[%index]; } print("Total pieces of Fruit:" @ %numFruit);

20 Dr. Ken Hoganson, Kennesaw State University fruitloopy.cs // now calculate the total cost for (%index = 0; %index <= %numFruitTypes; %index++) { %totalCost = %totalCost + (%quantity[%index]*%cost[%index]); } print("Total Price of Fruit:$" @ %totalCost); }

21 Dr. Ken Hoganson, Kennesaw State University Running programs My CD did not include an IDE Runs from a DOS window Open from the “start search” input bar: ◦ Type “command” Open file with an editor (can use notepad or any editor) Open file explore to view the directory (folder) and move/copy/delete files

22 Dr. Ken Hoganson, Kennesaw State University DOS The prompt shows your current location (drive:directory/subdirectory) Directories are folders dir - shows current directory contents cd - “change directory” can move up and down in the directory structure. ie cd ch2 - will move from the current location into a subdirectory called ch2 cd.. - will move up one level in the tree

23 Dr. Ken Hoganson, Kennesaw State University tge From the command prompt Change into the Torque folder which is 3DGPAi1 cd c:\3dgpai1 Prompt now shows: c:\3dgpai1> The torque executable is here (tge.exe) Can execute programs from here, or in subdirectories: tge –ch2 fruit.cs

24 Copyright © 2008, 2009, Dr. Ken Hoganson End of Lecture End Of Today’s Lecture.

25 CS 8625. Dr. Ken Hoganson, Copyright © 2009 This slide intentionally left blank


Download ppt "Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming."

Similar presentations


Ads by Google