Unable to find object error
by Jon Jorajuria · in Torque Game Engine · 01/06/2006 (11:56 am) · 5 replies
I am trying to spawn players and assign inventory based on the player Databock assigned from a character selection screen. I am trying to figure out where I am going wrong with this code. I get the following errors:
fps/server/scripts/game.cs (361): Unable to find object: '' attempting to call function 'setTransform'
fps/server/scripts/game.cs (362): Unable to find object: '' attempting to call function 'setShapeName'
fps/server/scripts/game.cs (365): Unable to find object: '' attempting to call function 'getEyeTransform'
Here is the player create function code:
function GameConnection::createPlayer(%this, %spawnPoint, %armor)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
%this.player.kill("suicide");
}
%this.armor = %armor;
switch(%armor)
{
case 1:
// Create the player object
%player = new Player()
{
dataBlock = modelA;
client = %this;
};
%player.setInventory(Sword,1);
%player.setInventory(pistol,1);
%player.setInventory(Ammo,10);
%player.mountImage(pistolImage,0);
break;
case 2:
// Create the player object
%player = new Player()
{
dataBlock = modelB;
client = %this;
};
%player.setInventory(Crossbow,1);
%player.setInventory(Ammo,10);
%player.mountImage(Crossbow,0);
break;
}
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint); //<-----Error
%player.setShapeName(%this.name); //<-----Error
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform()); //<-----Error
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}
Any clues would be much appreciated. Thank you in advanced for your time and help.
fps/server/scripts/game.cs (361): Unable to find object: '' attempting to call function 'setTransform'
fps/server/scripts/game.cs (362): Unable to find object: '' attempting to call function 'setShapeName'
fps/server/scripts/game.cs (365): Unable to find object: '' attempting to call function 'getEyeTransform'
Here is the player create function code:
function GameConnection::createPlayer(%this, %spawnPoint, %armor)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
%this.player.kill("suicide");
}
%this.armor = %armor;
switch(%armor)
{
case 1:
// Create the player object
%player = new Player()
{
dataBlock = modelA;
client = %this;
};
%player.setInventory(Sword,1);
%player.setInventory(pistol,1);
%player.setInventory(Ammo,10);
%player.mountImage(pistolImage,0);
break;
case 2:
// Create the player object
%player = new Player()
{
dataBlock = modelB;
client = %this;
};
%player.setInventory(Crossbow,1);
%player.setInventory(Ammo,10);
%player.mountImage(Crossbow,0);
break;
}
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint); //<-----Error
%player.setShapeName(%this.name); //<-----Error
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform()); //<-----Error
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}
Any clues would be much appreciated. Thank you in advanced for your time and help.
About the author
#2
Set::add: Object "" doesn't exist
01/06/2006 (12:57 pm)
Still getting the same error, but thank you for the suggestion...I just learned something new. I get this before the other errors, I don't know if this can be of help:Set::add: Object "" doesn't exist
#3
fps/server/scripts/game.cs (361): Unable to find object: '' attempting to call function 'setTransform'
fps/server/scripts/game.cs (362): Unable to find object: '' attempting to call function 'setShapeName'
fps/server/scripts/game.cs (365): Unable to find object: '' attempting to call function 'getEyeTransform'
03/09/2006 (4:06 pm)
I think this has to do with your player model not being loaded correctly. These functions basically hook the client to the player model's cameda node and controls, which is what it can't find.fps/server/scripts/game.cs (361): Unable to find object: '' attempting to call function 'setTransform'
fps/server/scripts/game.cs (362): Unable to find object: '' attempting to call function 'setShapeName'
fps/server/scripts/game.cs (365): Unable to find object: '' attempting to call function 'getEyeTransform'
#4
When you leave the switch body, %player is no longer defined (it's out of scope), and therefore cannot be used as you did inside the switch body. You'll want to move the creation of the %player object outside of the switch statement.
Note: a much easier way to set this up is to name your datablocks such that they are named exactly what is sent in the %armor parameter. Then you can just do this:
%player = new Player() {
datablock = %armor;
client = %this;
};
Then you don't need a switch statement at all.
03/09/2006 (4:49 pm)
You are setting your %player variable inside your switch body, as a locally scoped object.When you leave the switch body, %player is no longer defined (it's out of scope), and therefore cannot be used as you did inside the switch body. You'll want to move the creation of the %player object outside of the switch statement.
Note: a much easier way to set this up is to name your datablocks such that they are named exactly what is sent in the %armor parameter. Then you can just do this:
%player = new Player() {
datablock = %armor;
client = %this;
};
Then you don't need a switch statement at all.
#5
Also, rather then using a switch statement, I don't like using a switch for player selection / equiptment, creates unforseen problems down the track, you can seperate your equip function.
Example:
And the equip function
03/09/2006 (4:57 pm)
I agree with Stephen. Also, rather then using a switch statement, I don't like using a switch for player selection / equiptment, creates unforseen problems down the track, you can seperate your equip function.
Example:
function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
// Create the player object
%player = new Player() {
dataBlock = %this.armor;
client = %this;
};
MissionCleanup.add(%player);
//Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Starting equipment for Defence players
if (%this.armor $= "DefenceRifleman")
GameConnection::equipDefenceRifle(%player);
if (%this.armor $= "DefenceMedic")
GameConnection::equipDefenceMedic(%player);
if (%this.armor $= "DefenceSniper")
GameConnection::equipDefenceSniper(%player);
// Starting equipment for Assault players
if (%this.armor $= "AssaultRifleman")
GameConnection::equipAssaultRifle(%player);
if (%this.armor $= "AssaultMedic")
GameConnection::equipAssaultMedic(%player);
if (%this.armor $= "AssaultEngineer")
GameConnection::equipAssaultEngineer(%player);
//Safety feature. If for some strange reason client armor
//isn't found it will default to this. This shouldn't happen if all
//players & equiptment are set up correctly.
if (%this.armor !$= "DefenceRifleman" && %this.armor !$= "DefenceMedic" && %this.armor !$= "DefenceSniper" &&
%this.armor !$= "AssaultRifleman" && %this.armor !$= "AssaultMedic" && %this.armor !$= "AssaultEngineer") {
error("No equiptment found for " @ %this.armor @ " equiping player with defaults");
GameConnection::equipDefault(%player);
}
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}And the equip function
function GameConnection::equipDefenceRifle(%player)
{
echo("-->Defence Rifleman weapon layout loaded");
// Starting equipment
%player.setInventory(Styer,1);
%player.setInventory(StyerAmmo,30);
%player.setInventory(StyerAmmoClip,3);
%player.use(Styer);
}
function GameConnection::equipDefenceMedic(%player)
{
echo("-->Defence Medic weapon layout loaded");
// Starting equipment
%player.setInventory(medicKit,1);
%player.setInventory(Styer,1);
%player.setInventory(StyerAmmo,30);
%player.setInventory(StyerAmmoClip,3);
%player.use(medicKit);
}
...and so on
Torque Owner Jake Oster
If %armor isn't 1 or 2, %player won't be initialized, and would cause the errors you're seeing.