Gettnig subclassed Player, PlayerData to load in Game
by Jeffrey Bakker · in Torque Game Engine · 10/12/2005 (2:39 pm) · 3 replies
I have subclassed Player and PlayerData in the C++ code, to meet the needs of an RPG system. I've declared the two classes as conobjects and implemented RolePlayer and RolePlayerData as a netobject and datablock, respectively. To make sure the RolePlayer references RolePlayerData via mDataBlock (mmmmmm...DataBlock LOL), I overloaded the onNewDataBlock() method as follows:
I hope this isn't wrong, and I hope I'm not missing out anything crucial on the C++ side, but it compiles fine and I can't think of anything else that needs to be changed. Now I'm wondering what steps I need to get it loaded into the TorqueScript code properly...
In server/scripts.game.cs, I changed CreatePlayer() so it reads:
And in server/scripts/player.cs, I've changed the PlayerBody datablock from:
to
And from searching the forum, I found out I also needed to change a class name in weapon.cs at Weapon::OnPickup(), so I have done that also.
So now, I give it a go, and the game just crashes when I try to launch a mission. What am I missing or doing wrong?
bool RolePlayer::onNewDataBlock(GameBaseData* dptr)
{
PlayerData* prevData = mDataBlock;
mDataBlock = dynamic_cast<RolePlayerData*>(dptr);
//...I hope this isn't wrong, and I hope I'm not missing out anything crucial on the C++ side, but it compiles fine and I can't think of anything else that needs to be changed. Now I'm wondering what steps I need to get it loaded into the TorqueScript code properly...
In server/scripts.game.cs, I changed CreatePlayer() so it reads:
// Create the player object
%player = new RolePlayer() {
dataBlock = PlayerBody;
client = %this;
};And in server/scripts/player.cs, I've changed the PlayerBody datablock from:
datablock PlayerData(PlayerBody)
to
datablock RolePlayerData(PlayerBody)
And from searching the forum, I found out I also needed to change a class name in weapon.cs at Weapon::OnPickup(), so I have done that also.
So now, I give it a go, and the game just crashes when I try to launch a mission. What am I missing or doing wrong?
#2
Ran the game through the debugger, and it stops at:
Where the expressions of addr and sz of "this" cannot be evaluated. I'm guessing that's has to do with loading the shapeFile from the RolePlayerData datablock?
I checked console.log and interesting enough the last few lines are:
I never changed the ammo.dts file (but just in case, I installed a fresh copy of the file), so that's probably not it. What does it mean there's validation required for shape? Does that mean I have to manually do that in the RolePlayerData::preload() method? The game still loads another .cs script after this before crashing.
Any suggestions?
10/12/2005 (3:26 pm)
UPDATE:Ran the game through the debugger, and it stops at:
--- c:\torque\sdk\engine\ts\tsmesh.h --------------------------------------------------------------------------------------
39: bool empty() const { return sz==0; }
40: A & operator[](U32 idx) { return addr[idx]; }Where the expressions of addr and sz of "this" cannot be evaluated. I'm guessing that's has to do with loading the shapeFile from the RolePlayerData datablock?
I checked console.log and interesting enough the last few lines are:
Engine initialized... *** Load Main Menu Exporting server prefs... Loading compiled script prototype.rpg/server/scripts/audioProfiles.cs. Loading compiled script prototype.rpg/server/scripts/camera.cs. Loading compiled script prototype.rpg/server/scripts/markers.cs. Loading compiled script prototype.rpg/server/scripts/triggers.cs. Loading compiled script prototype.rpg/server/scripts/inventory.cs. Loading compiled script prototype.rpg/server/scripts/shapeBase.cs. Loading compiled script prototype.rpg/server/scripts/item.cs. Loading compiled script prototype.rpg/server/scripts/health.cs. Loading compiled script prototype.rpg/server/scripts/staticShape.cs. Loading compiled script prototype.rpg/server/scripts/weapon.cs. Loading compiled script prototype.rpg/server/scripts/radiusDamage.cs. Loading compiled script prototype.rpg/server/scripts/crossbow.cs. ParticleEmitterData(CrossbowBoltEmitter) velocityVariance > ejectionVelocity Error: shape prototype.rpg/data/shapes/crossbow/ammo.dts-collision detail 0 (Collision-3) bounds box invalid! Loading compiled script prototype.rpg/server/scripts/player.cs. Loading compiled script prototype.rpg/data/shapes/player/player.cs. Validation required for shape: prototype.rpg/data/shapes/player/player.dts Loading compiled script prototype.rpg/server/scripts/chimneyfire.cs.
I never changed the ammo.dts file (but just in case, I installed a fresh copy of the file), so that's probably not it. What does it mean there's validation required for shape? Does that mean I have to manually do that in the RolePlayerData::preload() method? The game still loads another .cs script after this before crashing.
Any suggestions?
#3
Examining the log file and comparing it to game.cs, I have noticed load order of scripts. The next script to be loaded was aiPlayer.cs before it crashes. So I changed the PlayerData to the RolePlayerData datablock in aiPlayer as well.
The game doesn't crash anymore, yet I still have to test myt class out.
10/12/2005 (5:17 pm)
ConclusionExamining the log file and comparing it to game.cs, I have noticed load order of scripts. The next script to be loaded was aiPlayer.cs before it crashes. So I changed the PlayerData to the RolePlayerData datablock in aiPlayer as well.
The game doesn't crash anymore, yet I still have to test myt class out.
Torque Owner Artur Hallmann
the c++ code for dynamic cast looks alright.