# 3D Game Programming All In One Book

This topic is 4798 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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...

##### Share on other sites
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.

##### Share on other sites
Thank you very much Witch Lord

##### Share on other sites
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

##### Share on other sites
I've made all the necessary changes even capitalizing M in Main, but its still saying its unable to find function main.

##### Share on other sites
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;

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
<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

##### Share on other sites
Quote:
 Original post by DarkoSome 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.bakCompiling 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 mainI'm about to give up with this. I've been trying to figure it out for the past 2 days.

you appear to have a parethesis mismatch in yor original code, I noticed a ( instead of a { you may also be missing a for loop declaration which is in corliss's version
if you've fixed that and the semi colons, it should work...if not, reprint the code your trying to compile rather than the error and lts see what the current state of your code is.

edit yes just checked the code in the book, you've actually made a couple of errors in the code when typing it in, and missed out 3 for loop declarations....its also a good idea to type in the comments when transcribing book code. it can helpyou see through errors like that.

##### Share on other sites
I'm such a dumb @#\$!. I thought the For loop code was part of the book comments and I didn't need to put it in there. Thanks guys it should work now!

##### Share on other sites
nope when source code is printed like that, only text after // or between /* */ can be considered comments...but you should still type them in..would have stopped this happening :)