Problems creating a custom object from script
by James Steele · in Torque Game Engine · 06/10/2005 (3:12 am) · 3 replies
My appologies in advance for cross-posting this, but this is driving me nuts. I'm using the starter.racing example as a foundation for starting my own project.
I have created a class derived from Vehicle, and haves exposed it to the Console using the DECLARE_CONOBJECT and IMPLEMENT_CO_NETOBJECT_V1 macros.
I create the class using the following Script code;
However...when the mission starts and I go to the console, I get the following error
I don't have a clue as to what I could be doing wrong to get this error. Can anybody point me in the right direction?
I have created a class derived from Vehicle, and haves exposed it to the Console using the DECLARE_CONOBJECT and IMPLEMENT_CO_NETOBJECT_V1 macros.
I create the class using the following Script code;
function GameConnection::createTank(%this, %spawnPoint)
{
if (%this.OpHoverTank > 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
%tank = new COpHoverVehicle() {
dataBlock = HeavyTank;
client = %this;
};
MissionCleanup.add(%tank);
// Player setup...
%tank.setTransform(%spawnPoint);
%tank.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%tank.getEyeTransform());
// Give the client control of the player
%this.OpHoverTank = %tank;
}However...when the mission starts and I go to the console, I get the following error
Game/server/scripts/game.cs (341): Register object failed for object (null) of class COpHoverVehicle.
I don't have a clue as to what I could be doing wrong to get this error. Can anybody point me in the right direction?
About the author
#2
So the datablock is being created, and referenced okay. The only thing left is to see what happens when I take out the assignment for the client member.
06/10/2005 (4:06 am)
I tried renaming the datablock from HeavyTank to MyHeavyTank and leaving the reference to HeavyTank to see what would happen. I get an error before the 'register object' one complaining that; 'HeavyTank' is not a member of the 'GameBaseData' data block class.So the datablock is being created, and referenced okay. The only thing left is to see what happens when I take out the assignment for the client member.
#3
Thanks for the help Matthew, it put me on the right track.
06/10/2005 (6:17 am)
I've fixed it now. I was actually forgetting to call Parent::initPersistFields() and also scriptOnNewDataBlock(). Thanks for the help Matthew, it put me on the right track.
Associate Matt Fairfax
PopCap