3D Game Programming All In One Book

Started by
11 comments, last by Patrick StarFish 19 years, 3 months ago
I'm a rookie in programming, even though I took Visual Basic at ITT Tech. I've never encountered Torque Script before, but I'm just working through the excercises in Kenneth C. Finey's book about 3D programming. Here's the code: function main() { %numFruitTypes = 5 %bananaIdx=0 %appleIdx=1 %orangeIdx=2 %mangoIdx=3 %pearIdx=4 %names[%bananaIdx] = "bananas"; %names[%appleIdx] = "apples"; %names[%orangeIdx] = "oranges"; %names[%mangoIdx] = "mangos"; %names[%pearIdx] = "pears"; %cost[%bananaIdx] = 1.15; %cost[%appleIdx] = 0.55; %cost[%orangeIdx] = 0.55; %cost[mangoIdx] = 1.90; %cost[%pearIdx] = 0.68; %quantity[%bananaIdx] = 1; %quantity[%appleIdx] = 3; %quantity[%orangeIdx] = 4; %quantity[%mangoIdx] = 1; %quantity[%pearIdx] = 2; %numFruit=0; %totalCost=0 ( print("Cost of " @ %names[%index] @ ":$" @ %cost[%index]); print("Number of " @ %names[%index] @ ":" @ %quantity[%index]); } { %numFruit = %numFruit + %quantity[%index]; } print("Total pieces of Fruit:" @ %numFruit); { %totalCost = %totalCost + (%quantity[%index]*%cost[%index]); } print("Total Price of Fruit:$" @ %totalCost); } I entered this code exactly and it gave me an error saying "Unable to Find Function Main." I'm like what the hell man I just typed function main() at the beginning! This thing happened before with Fruit.cs because I capitalized "Function." I just uncapitalized it and it ran. I do the same thing with this and it's giving me this unable to find function main stuff. Question 2: Should I learn C++ before I mess with Torque?
Advertisement
i think it'll be better for you to learn C/C++ before learning the scripting your book is using for whatever it is used for...
I'm not familiar with this script language, nor with the book you're referring to, but my guess is that it expects the Main function to be written with a capital M. Just as it is written in the error message.

I'm moving this post to the scripting languages forum so that you may get more help from those who frequent that forum.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thank you very much Witch Lord
This is not correct. Not sure if it is a typo in the post or not. Anyways in main you have:

%totalCost=0
(

It should be:
%totalCost=0;
}

I am not sure what the rest of the code is after this as it makes no sense. I have the book at home and will take a look at it.

As for what to learn first, go with TorqueScript. Why - gives you the basic syntax of how things work without having to deal with some of the nastier side of C/C++. =)

If you have any questions about Torque feel free to PM me. I am currently using it for a game project and I am fairly knowledgeable about it.

Chris
I've made all the necessary changes even capitalizing M in Main, but its still saying its unable to find function main.
right at the beginning of your main() function you have the following:

%numFruitTypes = 5

%bananaIdx=0
%appleIdx=1
%orangeIdx=2
%mangoIdx=3
%pearIdx=4

I believe each line should have a semicolon after them, like this:

%numFruitTypes = 5;

%bananaIdx=0;
%appleIdx=1;
%orangeIdx=2;
%mangoIdx=3;
%pearIdx=4;
you'd be better off checking out www.garagegames.com where they have a forum dedicated to Ken's book and fixing some of the errors in it.

Some guy at garage games.com told me I missed a load of semicolons. I fixed that, but now its giving me a different error message:
FruitLoopy.cs.bak
Compiling CH2/FruitLoopy.cs.bak...
CH2/FruitLoopy.cs.bak Line: 31 - Syntax error.
>>> Advanced script error report. Line 61.
>>> Some error context, with ## on sides of error halt:
%quantity[%mangoIdx] = 1;

%quantity[%pearIdx] = 2;



%numFruit=0;

%totalCost=0;

{##
##
print("Cost of " @ %names[%index] @ ":$" @ %cost[%index]);

print("Number of " @ %names[%index] @ ":" @ %quantity[%index
>>> Error report complete.

Executing CH2/FruitLoopy.cs.bak.
CH2/FruitLoopy.cs.bak Line: 31 - Syntax error.
>>> Advanced script error report. Line 61.
>>> Some error context, with ## on sides of error halt:
%quantity[%mangoIdx] = 1;

%quantity[%pearIdx] = 2;



%numFruit=0;

%totalCost=0;

{##
##
print("Cost of " @ %names[%index] @ ":$" @ %cost[%index]);

print("Number of " @ %names[%index] @ ":" @ %quantity[%index
>>> Error report complete.

CH2/run.cs (30): Unable to find function main
I'm about to give up with this. I've been trying to figure it out for the past 2 days.
<code>
function main()
{
%numFruitTypes = 5;

%bananaIdx=0;
%appleIdx=1;
%orangeIdx=2;
%mangoIdx=3;
%pearIdx=4;

%names[%bananaIdx] = "bananas";
%names[%appleIdx] = "apples";
%names[%orangeIdx] = "oranges";
%names[%mangoIdx] = "mangos";
%names[%pearIdx] = "pears";

%cost[%bananaIdx] = 1.15;
%cost[%appleIdx] = 0.55;
%cost[%orangeIdx] = 0.55;
%cost[mangoIdx] = 1.90;
%cost[%pearIdx] = 0.68;

%quantity[%bananaIdx] = 1;
%quantity[%appleIdx] = 3;
%quantity[%orangeIdx] = 4;
%quantity[%mangoIdx] = 1;
%quantity[%pearIdx] = 2;

%numFruit=0;
%totalCost=0;

for (%index = 0; %index < %numFruitTypes; %index++) {
echo("Cost of " @ %names[%index] @ ":$" @ %cost[%index]);
echo("Number of " @ %names[%index] @ ":" @ %quantity[%index]);

%numFruit = %numFruit + %quantity[%index];

echo("Total pieces of Fruit:" @ %numFruit);

%totalCost = %totalCost + (%quantity[%index]*%cost[%index]);

echo("Total Price of Fruit:$" @ %totalCost);
}
}
</code>

This works. Just ran it with torque with no problems. Maybe it will help you figure out what is going on.

Chris

This topic is closed to new replies.

Advertisement