2D Game Building for Teens chaper 7 enemy.cs
by Alex Head · in Torque Game Builder · 02/12/2011 (9:32 am) · 2 replies
I'm plodding through this horrible book hoping to learn something. I've managed to research all of the problems up to this point but now I've hit a wall with my enemy.cs script.
function MeanBat::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityX(-getRandom(%this.minSpeed, %this.maxSpeed));
}
function MeanBat::onWorldLimit(%this, %mode, %limit)
{
switch$(%limit)
{
case "left";
%this.setFlipX(true);
%this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-35, 35));
case "right";
%this.setFlipX(false);
%this.setLinearVelocityX(-getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-35, 35));
}
}
I've found a few of the problems and adjusted the code from what was in the book, but problems remain. The code never gets exicuted as there seems to be something wrong with the setLinearVelocityX lines. I do not see the problem.
any clue would be appreciated.
alex
function MeanBat::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityX(-getRandom(%this.minSpeed, %this.maxSpeed));
}
function MeanBat::onWorldLimit(%this, %mode, %limit)
{
switch$(%limit)
{
case "left";
%this.setFlipX(true);
%this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-35, 35));
case "right";
%this.setFlipX(false);
%this.setLinearVelocityX(-getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-35, 35));
}
}
I've found a few of the problems and adjusted the code from what was in the book, but problems remain. The code never gets exicuted as there seems to be something wrong with the setLinearVelocityX lines. I do not see the problem.
any clue would be appreciated.
alex
Torque Owner Tomas Lazaro
BelfryGames
The immediate problem I can see is in the switch statement. Please refer to http://docs.garagegames.com/tgea/official/content/documentation/Scripting%20Reference/Introduction/TorqueScript.html#Branching_Structures for details.
switch$(...) <- correct when using strings
...
case "left"; <- ';' should be ':'
...
case "right"; <- ';' should be ':'
I think that's pretty much it. If it still doesn't work please post again.