My fish won't grow, shrink, or die.
by Rebecca Herndon · in Torque Game Builder · 07/07/2009 (8:29 pm) · 3 replies
I know that this is a noob thing, but I I can't seem to fix my script for the life of me. I can't even call up the debugger box with the ~ when I run the game, so I can't tell where the faulty script is. I've checked and reched, typed and retyped, and even copy and pasted.
here's my fish player code:
function Fish::getSpeed(%this)
{
return getRandom(%this.minSpeed, %this.maxSpeed);
}
function Fish::reposition(%this)
{
%this.setPositionY(getRandom(-45, 30));
}
function Fish::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityX(%this.getSpeed());
}
function Fish::onWorldLimit(%this, %mode, %limit)
{
switch$(%limit)
{
case "left":
%this.setFlipX(false);
%this.setLinearVelocityX(%this.getSpeed());
%this.reposition();
case "right":
%this.setFlipX(true);
%this.setLinearVelocityX(-%this.getSpeed());
%this.reposition();
}
}
here's my fish player code:
function Fish::getSpeed(%this)
{
return getRandom(%this.minSpeed, %this.maxSpeed);
}
function Fish::reposition(%this)
{
%this.setPositionY(getRandom(-45, 30));
}
function Fish::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityX(%this.getSpeed());
}
function Fish::onWorldLimit(%this, %mode, %limit)
{
switch$(%limit)
{
case "left":
%this.setFlipX(false);
%this.setLinearVelocityX(%this.getSpeed());
%this.reposition();
case "right":
%this.setFlipX(true);
%this.setLinearVelocityX(-%this.getSpeed());
%this.reposition();
}
}
#2
function PlayerFish::onLevelLoaded(%this, %scenegraph)
{
$FishPlayer = %this;
moveMap.bindCmd(keyboard, "up", "fishPlayerUp();", "fishPlayerUpStop();");
moveMap.bindCmd(keyboard, "down", "fishPlayerDown();", "fishPlayerDownStop();");
moveMap.bindCmd(keyboard, "left", "fishPlayerLeft();", "fishPlayerLeftStop();");
moveMap.bindCmd(keyboard, "right", "fishPlayerRight();", "fishPlayerRightStop();");
moveMap.bindCmd(keyboard, "space", "fishPlayerBoost();", "fishPlayerBoostSop();");
%this.lowerLife();
}
function fishPlayerUp()
{
$FishPlayer.moveUp = true;
$FishPlayer.updateMovement();
}
function fishPlayerDown()
{
$FishPlayer.moveDown = true;
$FishPlayer.updateMovement();
}
function fishPlayerLeft()
{
$FishPlayer.moveLeft = true;
$FishPlayer.updateMovement();
}
function fishPlayerRight()
{
$FishPlayer.moveRight = true;
$FishPlayer.updateMovement();
}
function fishPlayerUpStop()
{
$FishPlayer.moveUp = false;
$FishPlayer.updateMovement();
}
function fishPlayerDownStop()
{
$FishPlayer.moveDown = false;
$FishPlayer.updateMovement();
}
function fishPlayerLeftStop()
{
$FishPlayer.moveLeft = false;
$FishPlayer.updateMovement();
}
function fishPlayerRightStop()
{
$FishPlayer.moveRight = false;
$FishPlayer.updateMovement();
}
function fishPlayerBoost()
{
if($FishPlayer.dead)
return;
%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.dead)
return;
if(%this.moveLeft)
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( -FishPlayer.hSpeed );
}
if(%this.moveRight)
{
$FishPlayer.setFlipX(false);
$FishPlayer.setLinearVelovityX( $FishPlayer.hSpeed );
}
if(%this.moveUp)
{
%this.setLinearVelocityY( -$FishPlayer.vSpeed );
}
if(%this.moveDown)
{
%this.setLinearVelocityY( $FishPlayer.vSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
if(!%this.moveUp && !%this.moveDown)
{
}
function PlayerFish::modifyLife(%this, %dmg)
{
%this.life += %dmg;
if(%this.life > 100)
{
%this.life = 100;
} else if (%this.life < 0)
{
%this.life = 0;
}
if(%this.life <= 30)
{
%this.dead();
} else
{
%this.updateLifeSize();
}
}
function PlayerFish::updateLifeSize(%this)
{
%lifeMultiplier = %this.life / 100;
%newWidth = %this.maxWidth * %lifeMultiplier;
%newHeight = %this.maxHeight * %lifeMultiplier;
%this.setSize(%newWidth, %newHeight);
}
function PlayerFish::dead(%this)
{
%this.setFlipY(true);
%this.setLinearVelocityY(-10);
%this.dead = true;
}
function PlayerFish::lowerLife(%this)
{
%this.modifyLife(%this.lifeDrain);
if(!%this.dead)
{
%this.schedule(500, "lowerLife");
}
}
07/08/2009 (7:36 am)
Thanks for looking it over. I am not using the latest TGB. I posted the fish code though and not the player code <feeling sheepish>.function PlayerFish::onLevelLoaded(%this, %scenegraph)
{
$FishPlayer = %this;
moveMap.bindCmd(keyboard, "up", "fishPlayerUp();", "fishPlayerUpStop();");
moveMap.bindCmd(keyboard, "down", "fishPlayerDown();", "fishPlayerDownStop();");
moveMap.bindCmd(keyboard, "left", "fishPlayerLeft();", "fishPlayerLeftStop();");
moveMap.bindCmd(keyboard, "right", "fishPlayerRight();", "fishPlayerRightStop();");
moveMap.bindCmd(keyboard, "space", "fishPlayerBoost();", "fishPlayerBoostSop();");
%this.lowerLife();
}
function fishPlayerUp()
{
$FishPlayer.moveUp = true;
$FishPlayer.updateMovement();
}
function fishPlayerDown()
{
$FishPlayer.moveDown = true;
$FishPlayer.updateMovement();
}
function fishPlayerLeft()
{
$FishPlayer.moveLeft = true;
$FishPlayer.updateMovement();
}
function fishPlayerRight()
{
$FishPlayer.moveRight = true;
$FishPlayer.updateMovement();
}
function fishPlayerUpStop()
{
$FishPlayer.moveUp = false;
$FishPlayer.updateMovement();
}
function fishPlayerDownStop()
{
$FishPlayer.moveDown = false;
$FishPlayer.updateMovement();
}
function fishPlayerLeftStop()
{
$FishPlayer.moveLeft = false;
$FishPlayer.updateMovement();
}
function fishPlayerRightStop()
{
$FishPlayer.moveRight = false;
$FishPlayer.updateMovement();
}
function fishPlayerBoost()
{
if($FishPlayer.dead)
return;
%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.dead)
return;
if(%this.moveLeft)
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( -FishPlayer.hSpeed );
}
if(%this.moveRight)
{
$FishPlayer.setFlipX(false);
$FishPlayer.setLinearVelovityX( $FishPlayer.hSpeed );
}
if(%this.moveUp)
{
%this.setLinearVelocityY( -$FishPlayer.vSpeed );
}
if(%this.moveDown)
{
%this.setLinearVelocityY( $FishPlayer.vSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
if(!%this.moveUp && !%this.moveDown)
{
}
function PlayerFish::modifyLife(%this, %dmg)
{
%this.life += %dmg;
if(%this.life > 100)
{
%this.life = 100;
} else if (%this.life < 0)
{
%this.life = 0;
}
if(%this.life <= 30)
{
%this.dead();
} else
{
%this.updateLifeSize();
}
}
function PlayerFish::updateLifeSize(%this)
{
%lifeMultiplier = %this.life / 100;
%newWidth = %this.maxWidth * %lifeMultiplier;
%newHeight = %this.maxHeight * %lifeMultiplier;
%this.setSize(%newWidth, %newHeight);
}
function PlayerFish::dead(%this)
{
%this.setFlipY(true);
%this.setLinearVelocityY(-10);
%this.dead = true;
}
function PlayerFish::lowerLife(%this)
{
%this.modifyLife(%this.lifeDrain);
if(!%this.dead)
{
%this.schedule(500, "lowerLife");
}
}
#3
Matt
07/08/2009 (10:48 am)
I suggest you download a demo of Torsion and load the game project in that, it should quickly tell you which script is faulty. You can also set breakpoints with it, and step through the code.Matt
Torque 3D Owner Aaron Miller
Also, is your fish moving at all? I don't see any calls to set the size with what you've posted. If it's not moving, make sure the fish's script field is set correctly in the editor. (It looks like the class field should be set to Fish).