TorqueScript Problem
by Keith H · in Technical Issues · 02/20/2008 (9:46 am) · 3 replies
I am working in the book 3D Game Programming All in One by Ken Finney, and I have a problem. On page 81, I'm doing the activity Twoty Fruit where it introduces functions and their uses. I finished it, but whenever I try to put the code into Torque, in says there is a syntax error at line 80. I can't seem to understand what I did wrong. Can explain what's going on?
Here's the code:
//=========================================================================
// TwotyFruity.cs
//
// 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 FruitLoopy.cs module designed to demonstrate how to use
// functions.
//=========================================================================
function InitializeFruit()
//-------------------------------------------------------------------------
// Set the starting values for our fruit arrays, and the type
// indices
//
// RETURNS: number of different types of fruit
//
//-------------------------------------------------------------------------
{
%numTypes = 5; // so we know how many types are in our arrays
$bananaIdx = 0; // initialize the values of our index variables
$appleIdx = 1;
$orangeIdx = 2;
$mangoIdx = 3;
$pearIdx = 4;
$names[$bananaIdx] = "bananas"; //initialize fruit name values
$names[$appleIdx] = "apples";
$names[$orangeIdx] = "oranges";
$names[$mangoIdx] = "mangos";
$names[$pearIdx] = "pears";
$cost[$bananaIdx] = 1.15; //initialize the quantity values
$cost[$appleIdx] = 0.55;
$cost[$orangeIdx] = 0.55;
$cost[$mangoIdx] = 1.90;
$cost[$pearIdx] = 0.68;
$quantity[$bananaIdx] = 1; //initialize the quantity values
$quantity[$appleIdx] = 3;
$quantity[$orangeIdx] = 4;
$quantity[$mangoIdx] = 1;
$quantity[$pearIdx] = 2;
return(%numtypes);
}
function addEmUp(%numFruitTypes)
//-------------------------------------------------------------------------
// Add all prices of different fruit types to get a full total cost
//
//PARAMETERS: %numFruitTypes -The number of different of fruit that are tracked
//
// RETURNS: total cost of all fruit
//
//-------------------------------------------------------------------------
{
%total = 0;
for(%index = 0; %index <= %numFruitTypes; %index++)
{
%total = %total + ($quantity[%index]*$cost[%index]);
}
return %total;
}
//-------------------------------------------------------------------------
// countEm
//
// Add all quantities of different fruit types to get a full total
//
//PARAMETERS: %numFruitTypes -the number of different fruit that are tracked
//
// RETURNS: total of all fruit types
//
//-------------------------------------------------------------------------
function countEm(%numFruitTypes)
{
%total = 0
for(%index = 0; %index <= %numFruitTypes; %index++) THE PROBLEM IS RIGHT HERE, LINE 80!
{
%total = %total + %quantity[%index];
}
return %total;
}
-------------------------------------------------------------------------------------------------------------------------------------------
I marked the spot with the problem in all caps. Please help me! There is more code, but I exceeded maximux characters.
Here's the code:
//=========================================================================
// TwotyFruity.cs
//
// 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 FruitLoopy.cs module designed to demonstrate how to use
// functions.
//=========================================================================
function InitializeFruit()
//-------------------------------------------------------------------------
// Set the starting values for our fruit arrays, and the type
// indices
//
// RETURNS: number of different types of fruit
//
//-------------------------------------------------------------------------
{
%numTypes = 5; // so we know how many types are in our arrays
$bananaIdx = 0; // initialize the values of our index variables
$appleIdx = 1;
$orangeIdx = 2;
$mangoIdx = 3;
$pearIdx = 4;
$names[$bananaIdx] = "bananas"; //initialize fruit name values
$names[$appleIdx] = "apples";
$names[$orangeIdx] = "oranges";
$names[$mangoIdx] = "mangos";
$names[$pearIdx] = "pears";
$cost[$bananaIdx] = 1.15; //initialize the quantity values
$cost[$appleIdx] = 0.55;
$cost[$orangeIdx] = 0.55;
$cost[$mangoIdx] = 1.90;
$cost[$pearIdx] = 0.68;
$quantity[$bananaIdx] = 1; //initialize the quantity values
$quantity[$appleIdx] = 3;
$quantity[$orangeIdx] = 4;
$quantity[$mangoIdx] = 1;
$quantity[$pearIdx] = 2;
return(%numtypes);
}
function addEmUp(%numFruitTypes)
//-------------------------------------------------------------------------
// Add all prices of different fruit types to get a full total cost
//
//PARAMETERS: %numFruitTypes -The number of different of fruit that are tracked
//
// RETURNS: total cost of all fruit
//
//-------------------------------------------------------------------------
{
%total = 0;
for(%index = 0; %index <= %numFruitTypes; %index++)
{
%total = %total + ($quantity[%index]*$cost[%index]);
}
return %total;
}
//-------------------------------------------------------------------------
// countEm
//
// Add all quantities of different fruit types to get a full total
//
//PARAMETERS: %numFruitTypes -the number of different fruit that are tracked
//
// RETURNS: total of all fruit types
//
//-------------------------------------------------------------------------
function countEm(%numFruitTypes)
{
%total = 0
for(%index = 0; %index <= %numFruitTypes; %index++) THE PROBLEM IS RIGHT HERE, LINE 80!
{
%total = %total + %quantity[%index];
}
return %total;
}
-------------------------------------------------------------------------------------------------------------------------------------------
I marked the spot with the problem in all caps. Please help me! There is more code, but I exceeded maximux characters.
#2
As a general guideline: when you get reports of syntax errors in a line and yet you can't find anything there, check for missing comma's and semi-colons in the line(s) before that. Another thing to look for would be making sure () {} [] are paired up correctly. A missing closing bracket can cause the same problem.
02/20/2008 (10:48 am)
Julian pointed out the missing ; at the end of line 79. As a general guideline: when you get reports of syntax errors in a line and yet you can't find anything there, check for missing comma's and semi-colons in the line(s) before that. Another thing to look for would be making sure () {} [] are paired up correctly. A missing closing bracket can cause the same problem.
#3
02/20/2008 (11:13 am)
Thank you two very much.
Torque Owner Jules
Something2Play