Parse error
by Fucifer · in Torque Game Builder · 09/13/2006 (2:11 pm) · 10 replies
I doing this tutorial on TDN. No matter what I do I get paser error on line 131. Can anyone see what is wrong with the code. It is probably looking right at me but i dont see it. I have redone the tutorial about eight times and still the same error. This is lline 131 "function t2dSceneGraph::onUpdateScene()"
http://tdn.garagegames.com/wiki/TGB/MiniPlatformerTutorial
http://tdn.garagegames.com/wiki/TGB/MiniPlatformerTutorial
function playerClass::onLevelLoaded(%this, %scenegraph)
{
$pGuy = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
$pGuy.setCollisionMaxIterations(2);
%force = 20;
sceneWindow2D.mount($pGuy, "0 0", %force, true);
}
function playerLeft()
{
$pGuy.moveLeft = true;
$pGuy.setFlip(true, false);
}
function playerLeftStop()
{
$pGuy.moveLeft = false;
}
function playerRight()
{
$pGuy.moveRight = true;
$pGuy.setFlip(false, false);
}
function playerRightStop()
{
$pGuy.moveRight = false;
}
function playerJump()
{
%yVelocity = $pGuy.getLinearVelocityY();
%xVelocity = $pGuy.getLinearVelocityX();
$pGuy.setLinearVelocityY(100);
$pGuy.setLinearVelocityX(0);
%collision = $pGuy.castCollision(0.005);
if(!(%collision $= ""))
{
$pGuy.setLinearVelocityY(-225);
}
else
{
$pGuy.setLinearVelocityY(%yVelocity);
}
$pGuy.setLinearVelocityX(%xVelocity);
}
function playerClass::updateMovement(%this)
{
%yVelocity = $pGuy.getLinearVelocityY();
$pGuy.setCurrentAnimation();
$pGuy.setLinearVelocityY(0);
if(%this.moveLeft)
{
%this.setLinearVelocityX(-60);
}
if(%this.moveRight)
{
%this.setLinearVelocityX(60);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
%collision = $pGuy.castCollision(0.005);
if(%collision !$= "" )
{
$pGuy.setLinearVelocityX(0);
}
$pGuy.setLinearVelocityY(100);
%collision = $pGuy.castCollision(0.005);
$pGuy.setLinearVelocityY(%yVelocity );
if(%collision $= "")
{
$pGuy.setConstantForceY(100);
}
else
{
$pGuy.setConstantForceY(0);
}
}
function playerClass::setCurrentAnimation(%this, %yVelocity)
{
if(%yVelocity < 0 )
{
%this.playAnimation(playerJumpUp);
}
else if(%yVelocity > 0 )
{
%this.playAnimation(playerJumpDown);
}
else
{
if(%this.moveLeft || %this.moveRight)
{
if(%this.getAnimationName() $= "playerRun")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerStand);
}
}
function t2dSceneGraph::onUpdateScene()
{
$pGuy.updateMovement();
}
#2
should be *I think*
09/13/2006 (3:18 pm)
if(%yVelocity < 0 )
{
%this.playAnimation(playerJumpUp);
}
else if(%yVelocity > 0 )
{
%this.playAnimation(playerJumpDown);
}
else
{
if(%this.moveLeft || %this.moveRight)
{
if(%this.getAnimationName() $= "playerRun")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerStand);
}should be *I think*
if(%yVelocity < 0 )
{
%this.playAnimation(playerJumpUp);
}
else
{
if(%yVelocity > 0 )
{
%this.playAnimation(playerJumpDown);
}
else
{
if(%this.moveLeft || %this.moveRight)
{
if(%this.getAnimationName() $= "playerRun")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerStand);
}There were some curly braces missing. To make things simple, if you just have one line IF statements, you don't need braces. The following is valid:if ($foo == $bar)
echo ("values are equal);
else
echo ("values are not equal");That should help increase the readability of your code 10 fold :)
#3
Line 131
function t2dSceneGraph::onUpdateScene()
{ // error is here
09/13/2006 (5:10 pm)
Philp, Thanks for repy buy I still get the same error on the same line.Line 131
function t2dSceneGraph::onUpdateScene()
{ // error is here
#4
Also putting your code samples in code tags will maintain formatting and increase readability and ease of helping you in the future. You might want to edit your intial post and re-paste in your code with all formatting.
09/13/2006 (5:18 pm)
Try throwing %this in there, a la:function t2dSceneGraph::onUpdateScene(%this)
Also putting your code samples in code tags will maintain formatting and increase readability and ease of helping you in the future. You might want to edit your intial post and re-paste in your code with all formatting.
#5
09/13/2006 (5:30 pm)
Ben Thanks for reply but still the same. How would I put the code in the format like you and Philp has it. The code is format in cs file but when I copy and paste here it all move to the left.
#6
Use [ code ] Paste Your Code Here [/ code ] tags, without the spaces. That will use a font that will keep things spaced well.
09/13/2006 (5:32 pm)
@Michael:Use [ code ] Paste Your Code Here [/ code ] tags, without the spaces. That will use a font that will keep things spaced well.
#7
09/13/2006 (5:58 pm)
Thanks Stephen Zepp, for tags tip.
#8
You forgot to indent this block, and therefore forgot a close } at the end of the block, even though visually it lines up.
I'm not sure of Torsion does this, but I know a very handy tool within Ultra-Edit is the ability to match closing braces and parentheses--it will highlight all text between the open paren/brace and the correct close one.
09/13/2006 (7:23 pm)
And here's your problem section:{
if(%this.moveLeft || %this.moveRight)
{
if(%this.getAnimationName() $= "playerRun")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerStand);
}You forgot to indent this block, and therefore forgot a close } at the end of the block, even though visually it lines up.
I'm not sure of Torsion does this, but I know a very handy tool within Ultra-Edit is the ability to match closing braces and parentheses--it will highlight all text between the open paren/brace and the correct close one.
#9
09/14/2006 (8:32 am)
Thanks Stephen I will give it try. The error is still there.
#10
09/14/2006 (2:23 pm)
I final got to work. I had rearrange the function order in the player.cs. Thanks for help.
Torque Owner Ben R Vesco