Game Development Community

More fish collision problems

by Bay ARENAC ISD (#0001) · in Torque Game Builder · 04/14/2008 (6:10 am) · 4 replies

I'm having more trouble with the fish game tutorial. When the fish and the food collide nothing happens. I have the collision settings right in the level builder, send and receive collisions is set checked for the fish object, send and callback are checked for the food. Superscribe ellipse is unchecked, the buble is on circle, and the fish is on polygon wich I defined. I don't get any errors from the console on my fishfood script, but maybe theres something wrong with it. Here it is.
_________
function FishFood:: onLevelLoaded(%this, %scenegraph)
{
%this.startPosition = %this.getPosition();
%this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}

function FishFood:: onWorldLimit(%this, %mode, %limit)
{
if(%limit $= "bottom")
{
%this.spawn();
}
}

function FishFood::spawn(%this)
{
%this.setPosition(%this.startPosition);
%this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}

function FishFood::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(%dstObj.class $= "PlayerFish")
{
%srcObj.spawn();
}
}
_________

I do get one error in my script, but its in the player movement script which works fine.

if(%this.moveUp)
{
$setLinearVelocityY( -$FishPlayer.vSpeed ); (the error is on this line)
}



It says parse error, but the script still works just fine for player movement. I don't see how that is any diffrent than this section of cod that doesn't get any errors.

if(%this.moveDown)
{
$setLinearVelocityY( $FishPlayer.vSpeed );
}

#1
04/18/2008 (2:02 pm)
Hi. I'm just trialling TGB myself and having my own difficulties so forgive me if my comments seem a little clueless or unhelpful.

As far as i can tell, you're right about the section of the player movement script that shows an error being fine. In my (limited) experience though, the fact that it's showing an error there means that there is more than likely a missing or dulplicate '{' or '}' somewhere above that line that shows the error. I myself have always had problems spotting missing braces, but try posting the rest of your fish movement code here and i'll (and others) can have a look over it.

Hopefully we can get this sorted. I'm on the same tutorial having my own problems and it's frustrating and disheartening to be stuck so early on isn't it?
#2
04/18/2008 (3:15 pm)
It's critical that you not ignore parse errors, because the fact that it "appears to work fine" is very misleading, and here's why:

When Torque is loading a script file, it has two choices to pick from:

a .cs file, which is the actual TorqueScript (human readable) code file.

a .cs.dso file, which is a byte code compiled version of the .cs file, and is generated when a file is successfully compiled.

Now, if Torque fails to compile a .cs file,. instead of just giving up, it will look for a .dso file from a previous compilation attempt--and if it finds one, it uses it.

This can be confusing, because by definition it's old code--and therefore what you think is working is not what you just wrote.
#3
04/21/2008 (5:48 am)
Ok, heres the whole code. I can't find an uneven bracket anywhere, of course I'm horrible at finding things.

function PlayerFish::onLevelLoaded(%this, %scenegraph)
{
$FishPlayer = %this;


moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();");
moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();");
moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();");
moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();");
moveMap.bindCmd(keyboard, "space", "fishPlayerBoost();", "fishPlayerBoostStop();");
}

function fishPlayerBoost()
{
%flipX = $FishPlayer.getFlipX();
if(!%flipX)
{
%hSpeed = $FishPlayer.hSpeed * 3;
}
else
{
%hSpeed = -$FishPlayer.hSpeed * 3;
}
$FishPlayer.setLinearVelocityX(%hSpeed);
}

function fishPlayerBoostStop()
{
$FishPlayer.setLinearVelocityX(0);
}

function PlayerFish::updateMovement(%this)
{
if(%this.moveLeft)
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed );
}
if(%this.moveRight)
{
$FishPlayer.setFlipX(false);
$FishPlayer.setLinearVelocityX( $FishPlayer.hSpeed );
}
if(%this.moveUp)
{
$setLinearVelocityY( -$FishPlayer.vSpeed );
}
if(%this.moveDown)
{
$setLinearVelocityY( $FishPlayer.vSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
$setLinearVelocityX(0);
}
if(!%this.moveUp && !%this.moveDown)
{
$setLinearVelocityY(0);
}
}

function fishPlayerUp()
{
$FishPlayer.moveUp = true;
$FishPlayer.updateMovement();
}

function fishPlayerDown()
{
$FishPlayer.moveDown = true;
$FishPlayer.updateMovement();
}

function fishPlayerRight()
{
$FishPlayer.moveRight = true;
$FishPlayer.updateMovement();
}

function fishPlayerLeft()
{
$FishPlayer.moveLeft = true;
$FishPlayer.updateMovement();
}

function fishPlayerUpStop()
{
$FishPlayer.moveUp = false;
$FishPlayer.updateMovement();
}

function fishPlayerDownStop()
{
$FishPlayer.moveDown = false;
$FishPlayer.updateMovement();
}

function fishPlayerRightStop()
{
$FishPlayer.moveRight = false;
$FishPlayer.updateMovement();
}

function fishPlayerLeftStop()
{
$FishPlayer.moveLeft = false;
$FishPlayer.udpateMovement();
}
#4
05/08/2008 (2:26 pm)
Looking at my code from the tutorial it should be

if(%this.moveUp)
{
%this.setLinearVelocityY(-$FishPlayer.vSpeed);
}

I'd imagine that it could also be applied like this as well

if(%this.moveUp)
{
$FishPlayer.setLinearVelocityY(-$FishPlayer.vSpeed);
}