Unknown command getState
by Ken Davis · in Torque Game Engine · 10/25/2004 (10:33 am) · 8 replies
I am getting the following error in my console. The error is occuring when a player dies and the logic is looking to see if %obj.getState() $= "Dead", but the getState function is failing.. By the way, this is a vehicle player not a normal player or vehicle.
-Ken
control/server/scripts/tank.cs (283): Unknown command getState. Object (1455) HoverVehicle -> Vehicle -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObjectAny ideas?
-Ken
#2
Hope that helps shed a bit more light, I am not 100% sure it is correct but I believe it to be given the info you posted. Good luck
10/25/2004 (10:50 am)
May wish to check into the code on this. getState is a console method declared in player.cc calling another function also defined in player. If you wrote HoverVehicle based partially off player (for some routines rather then entirely off vehicle maybe) you might have forgetten to include this. If not likely can just add the relevant code pieces for the console method as well as the function and declaration that exists in player to your HoverVehicle code.Hope that helps shed a bit more light, I am not 100% sure it is correct but I believe it to be given the info you posted. Good luck
#3
This will return true or false.
10/27/2004 (3:16 pm)
GetState() is used with PlayerData not VehicleData. What you want to use is getDamageState() which will return Destroyed, Disabled or Enabled. You can also use, if your just checking for dead..if(%obj.isDestroyed())
This will return true or false.
#4
10/27/2004 (3:18 pm)
Or get the Damage Level also
#5
-Ken
11/02/2004 (12:10 pm)
Here is a few snippets of code where this function is used. You can see the getState() has been commented out and the isDestroyed() has been added.function HoverTank::onCollision(%this,%obj,%col,%vec,%speed)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
%obj_state = %obj.getState();
%col_className = %col.getClassName();
%col_dblock_className = %col.getDataBlock().className;
%colName = %col.getDataBlock().getName();
//if ( %obj_state $= "Dead")
if(%obj.isDestroyed())
return;
if (%col_className $= "Item" || %col_className $= "Weapon" ) // Deal with all items
{
%obj.pickup(%col); // otherwise, pick the item up
}
// Mount vehicles
//%this = %col.getDataBlock();
%pushForce = %obj.getDataBlock().pushForce; // Try to push the object away
if (!%pushForce)
%pushForce = 20;
%eye = %obj.getEyeVector(); // Start with the shape's eye vector...
%vec = vectorScale(%eye, %pushForce);
%vec = vectorAdd(%vec,%obj.getVelocity()); // Add the shape's velocity
%pos = %col.getPosition(); // then push
%vec = getWords(%vec, 0, 1) @ " 0.0";
%col.applyImpulse(%pos,%vec);
}
function DefaultTank::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
//if (%obj.getState() $= "Dead")
if(%obj.isDestroyed())
return;
%obj.applyDamage(%damage);
%location = "Body";
// Deal with client callbacks here because we don't have this
// information in the onDamage or onDisable methods
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0;
//if (%obj.getState() $= "Dead")
if(%obj.isDestroyed())
{
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
function DefaultTank::onDamage(%this, %obj, %delta)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
// This method is invoked by the ShapeBase code whenever the
// object's damage level changes.
//if (%delta > 0 && %obj.getState() !$= "Dead")
if (%delta > 0 %% %obj.isDestroyed())
{
// Increment the flash based on the amount.
%flash = %obj.getDamageFlash() + ((%delta / %this.maxDamage) * 2);
if (%flash > 0.75)
%flash = 0.75;
if (%flash > 0.001)
{
%obj.setDamageFlash(%flash);
}
%obj.setRechargeRate(0.01);
%obj.setRepairRate(0.01);
}
}Is this right?-Ken
#6
11/04/2004 (9:39 am)
Yes that is correct except that you have an error. Corrected:function DefaultTank::onDamage(%this, %obj, %delta)
{
// This method is invoked by the ShapeBase code whenever the
// object´s damage level changes.
//if (%delta > 0 && %obj.getState() !$= "Dead")
//if (%delta > 0 %% %obj.isDestroyed())
if (%delta > 0 && !%obj.isDestroyed())
{
// Increment the flash based on the amount.
%flash = %obj.getDamageFlash() + ((%delta / %this.maxDamage) * 2);
if (%flash > 0.75)
%flash = 0.75;
if (%flash > 0.001)
{
%obj.setDamageFlash(%flash);
}
%obj.setRechargeRate(0.01);
%obj.setRepairRate(0.01);
}
}
#7
11/06/2004 (12:06 pm)
Ok, I have tried this with %obj.isDestroyed() and %obj.getDamageState(). My players do not die using either one. I can see the tank taking damage because the cursor shows their level, but I can knock them down to zero, but they don't die? You can see that the function DefaultTank::damage calls.if (%obj.getDamageState() $= "Destroyed")
//if(%obj.isDestroyed())
{
echo ("\n\n***************Player Died***********\n");
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}Is this the onDeath function this function in the game.cs file??function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
// Clear out the name on the corpse
%this.player.setShapeName("");
// Switch the client over to the death cam and unhook the player object.
if (isObject(%this.camera) && isObject(%this.player)) {
//%this.camera.setMode("Corpse",%this.player);
%this.setControlObject(%this.camera);
}
%this.player = 0;
// Doll out points and display an appropriate message
if (%damageType $= "Suicide" || %sourceClient == %this) {
%this.incScore(-1);
messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
}
else {
%sourceClient.incScore(1);
messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
if (%sourceClient.score >= $Game::EndGameScore)
cycleGame();
}
}
#8
Hope that helps you out :-)
05/08/2007 (11:09 am)
Sorry to wake up a dead thread. Ken, you need to have a DefaultTank::onDestroyed() function in the vehicle .cs file. You can put whatever code you need in there, like unmounting the player, killing the player, unmounting weapon images, and setting $movementSpeed to zero to prevent movement.Hope that helps you out :-)
Associate Anthony Rosenbaum