Torque 1.5 - Introductory Tutorial scripting trouble
by Scott Fowler · in Technical Issues · 07/03/2007 (9:01 pm) · 2 replies
Hey, love the engine! I just went through the Introductory Tutorial for Torque 1.5, and I can't seem to get a certain part of the scripting to work.
The tutorial has you create multiple StaticShape logos in a mission and group them in a simgroup called 'logos', and adds this code to the serverside script associated with the logos:
function TorqueLogoItem::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $="Player")
{
%client = %col.client;
%client.score++;
commandToClient(%client, 'SetScoreCounter', %client.score);
%obj.delete();
%logoCount = logos.getCount();
if(%logoCount > 0)
return;
commandToClient(%client, 'ShowVictory', %client.score);
}
}
Then it has you make clientGame.cs in /client with this code:
function clientCmdSetScoreCounter(%score)
{
ScoreCounter.setText("Score:" SPC %score);
}
function clientCmdShowVictory(%score)
{
MessageBoxYesNo("You Win!", "Would you like to restart the game?", "loadMyMission();", "quit();");
}
...and also has you set the main.cs to load the clientGame.cs in its initClient() function with this code:
exec("./client/clientGame.cs");
Oh, it also has you make a GuiTxtCtrl object in the PlayGui with the name ScoreCounter - referenced in the clientGame.cs by the function that is in turn called by the logos' onCollision function, so that when the player touches a logo, the logo should dissapear and his score should increase by one.
I've read over the tutorial and checked each component file several times now, but it still doesn't work quite like the tutorial meant it to, for some reason. The logos are being destroyed, as they should be, and the command "clientCmdSetScoreCounter" is being called, but the console is reporting that the command is unknown! The ShowVictory function reports as unknown as well. This means that either clientGame.cs isn't being loaded, or the code in clientGame.cs has errors, right???
Is this a common newbie problem?
Help!!!
Thanks.
The tutorial has you create multiple StaticShape logos in a mission and group them in a simgroup called 'logos', and adds this code to the serverside script associated with the logos:
function TorqueLogoItem::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $="Player")
{
%client = %col.client;
%client.score++;
commandToClient(%client, 'SetScoreCounter', %client.score);
%obj.delete();
%logoCount = logos.getCount();
if(%logoCount > 0)
return;
commandToClient(%client, 'ShowVictory', %client.score);
}
}
Then it has you make clientGame.cs in /client with this code:
function clientCmdSetScoreCounter(%score)
{
ScoreCounter.setText("Score:" SPC %score);
}
function clientCmdShowVictory(%score)
{
MessageBoxYesNo("You Win!", "Would you like to restart the game?", "loadMyMission();", "quit();");
}
...and also has you set the main.cs to load the clientGame.cs in its initClient() function with this code:
exec("./client/clientGame.cs");
Oh, it also has you make a GuiTxtCtrl object in the PlayGui with the name ScoreCounter - referenced in the clientGame.cs by the function that is in turn called by the logos' onCollision function, so that when the player touches a logo, the logo should dissapear and his score should increase by one.
I've read over the tutorial and checked each component file several times now, but it still doesn't work quite like the tutorial meant it to, for some reason. The logos are being destroyed, as they should be, and the command "clientCmdSetScoreCounter" is being called, but the console is reporting that the command is unknown! The ShowVictory function reports as unknown as well. This means that either clientGame.cs isn't being loaded, or the code in clientGame.cs has errors, right???
Is this a common newbie problem?
Help!!!
Thanks.
About the author
#2
Thanks!
07/04/2007 (2:11 pm)
Hey, thanks for the help/pointers. Just wanted to say I found the problem. The log reported clientGame.cs as missing so I went to the file and I realized windows was hiding the common extension .cs from the filenames, and that I had added the .cs out of habit, which made the file read "clientGame.cs" but was actually "clientGame.cs.cs". Now it works.Thanks!
Employee Michael Perry
ZombieShortbus
You are most likely correct about the possible problem. There is either a syntax error before the script gets executed, inside the script before the functions are declared, or both.
Search console.log for "parse", "syntax", and "error". That should take you to any problems with the code.