![Page 1: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/1.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Introduction to Introduction to Torque Script Torque Script ProgrammingProgramming
![Page 2: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/2.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
On the CDTorqueUltraEdit32 (not required to use)Sound editor: AudacityShape editor: MilkShapePaintShop Pro (trial version)Building interior creation tool: QuArKVarious demos
![Page 3: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/3.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
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// ------------------------------------------------------------------------
![Page 4: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/4.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Example Torque Scriptfunction 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);}
![Page 5: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/5.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Example Torque Scriptfunction 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}
![Page 6: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/6.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Torque on the Webhttp://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.
![Page 7: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/7.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Modern ParadigmUsed 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.
![Page 8: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/8.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
VariablesDifferences 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.
![Page 9: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/9.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
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"); }
![Page 10: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/10.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
File extensionsNote the extension of
.cs
for Torque scripts.After “compiling”
.cs.dso
![Page 11: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/11.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
ExpressionsTerminate 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 “;”
![Page 12: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/12.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
keywordsbreakcasecontinuedefaultdoelsefalseforfunctionifnewreturnswitchtruewhile
![Page 13: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/13.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Variable namesMust not be a Torque keywordMust start with a letterMay contain only letters, numbers, or
underscoreNOT case sensitiveChoose meaningful namesSuggestion: 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)
![Page 14: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/14.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Scope%,$ used in front of variable name
% local variable – accessible only within the local function
$ global variable – accessible throughout the entire program
![Page 15: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/15.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
ArraysSquare brackets [ ] for arraysIndex is an integerNo 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
![Page 16: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/16.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Fruitloopy.csOn 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)
![Page 17: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/17.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
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 --------------------- //
![Page 18: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/18.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
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;
![Page 19: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/19.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
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);
![Page 20: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/20.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
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);}
![Page 21: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/21.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
Running programsMy CD did not include an IDERuns from a DOS windowOpen 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
![Page 22: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/22.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
DOSThe prompt shows your current
location (drive:directory/subdirectory)Directories are foldersdir - shows current directory contentscd - “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
![Page 23: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/23.jpg)
Dr. Ken Hoganson, Kennesaw State Dr. Ken Hoganson, Kennesaw State UniversityUniversity
tgeFrom the command promptChange into the Torque folder which
is 3DGPAi1cd 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
![Page 24: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/24.jpg)
Copyright © 2008, 2009, Copyright © 2008, 2009, Dr. Ken HogansonDr. Ken Hoganson End of LectureEnd of Lecture
End Of
Today’sLecture.
![Page 25: Dr. Ken Hoganson, Kennesaw State University Introduction to Torque Script Programming](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1b5503460f94c30b3b/html5/thumbnails/25.jpg)
CS 8625. Dr. Ken Hoganson, Copyright © 2009CS 8625. Dr. Ken Hoganson, Copyright © 2009
This slide intentionally left blank