Game Development Community

Object loosing its type.

by \"Robert Jaramillo\" · in Torque Game Builder · 02/19/2010 (12:48 pm) · 1 replies

What happens is when my harpoon collides with a fish I go to the on collision function and begin check what class the object is that I collided with. After determining this I pass in a point value to y retract function which returns my harpoon and adds to my score. However the problem is that I seem be having an issue where the on collision function doesn't recognize the invoking object as a harpoon because it keeps saying "" instead of harpoon. This of course is preventing my retract function from being called. below is the code for my harpoon class. Any help is appreciated.

///////////////////////////////////
//-------- On Level Load --------//
//- intialize our object values -//
///////////////////////////////////
function Harpoon::onLevelLoaded(%this, %scenegraph)
{
//global variable to store our Harpoon
$Harpoon = %this;
//////////////////////////////////////////////////////////
//NOTE: I Imagine that this is not an ideal solution //
//to inhertance with classes in torquescrpit. //
//Unfortunatley it was the best solution I saw //
//when searching through the forums and documentation //
//on the Toruqe Developer Network. I would love //
//to learn a better way to perform this task. //
//////////////////////////////////////////////////////////
%this.SuperClass = new t2dSceneObject();
}
///////////////////////////////////////////////
//-------- Intialize Our Object -------------//
//Set all default values for our object //
///////////////////////////////////////////////
function Harpoon::Intilization(%this)
{
//Set a bool to determine if we are ready to fire
%this.bIsReadyToFire = true;
//Set our harpoons rotation

//Set a value to storeour harpoons intial rotation. This prevents us
//from having to change a value in several different places in our code
//Calculation is (amount of degrees per sec divide by 60 due to 60 fps
%this.AngleIncrement = 0.333;

//Make sure that our harpoon starts in the middle of our player.
%this.setRotation(180);

%this.schedule(17, "Update");

}
////////////////////////////////////////////
//-------- Update Our Object -------------//
//rotate and update our ibjects properties//
////////////////////////////////////////////
function Harpoon::Update(%this)
{

//Cehck if we are ready to fire
if(%this.bIsReadyToFire == true)
{

//Check if we have gone past the range of our harpoon
if(((%this.getRotation() + %this.AngleIncrement)>= 240) ||
((%this.getRotation() + %this.AngleIncrement)<= -120))
{
//Since we were we toggle are increment value from positive to negative
%this.AngleIncrement *= -1;
}

//now we set our rotation by adding our current rotation to the correct increment
%this.setRotation(%this.getRotation() + %this.AngleIncrement);
}
%this.schedule(17, "Update");
}
///////////////////////////////////
//-------- Handle Input ---------//
//-- responses to player input --//
///////////////////////////////////
function Harpoon::Fire(%this)
{
%this.bIsReadyToFire = false;
%this.SetForwardMovementOnly(true);
%this.setForwardSpeed(20);
}
/////////////////////////////////////////////
//-------- Retract the Harpoon-------------//
//-- Returns harpoon to orginal position --//
/////////////////////////////////////////////
function Harpoon::Retract(%this, %points)
{
if(%this.getPosition() == $PlayerCenter)
{
$Player.InceraseScore(%points);
%this.bIsReadyToFIre = true;
return;
}
else
{
//check if we have been in this function before
if(%this.getForwardMovementOnly() == true)
{
%this.SetForwardMovementOnly(false);
%this.setForwardSpeed(0);
%this.setVelocity(-20);

}
%this.schedule(17, "Retract", %points);

}
return;
}
/////////////////////////////////////////////
//-------- Handle Collision ---------------//
//-- responses to collision with objects --//
/////////////////////////////////////////////
function Harpoon::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{

switch$ (%dstObj.class)
{
case "Fish":
%this.Retract(%this,10);
return;

case "CrazyFish":

%this.Retract(%this,10);
return;
}
}
///////////////////////////////////////////////
//-------- Handle World Limits --------------//
//-- response to world limit callback event--//
///////////////////////////////////////////////
function Harpoon::onWorldLimit(%this, %mode, %limit)
{
%this.Retract(%this,10);
}

#1
02/19/2010 (2:52 pm)
You can use the code tags to keep your code formatting, such as:

[ code]
echo("test");
[ /code]

Just remove the spaces after the beginning bracket.