Wierdness in ShapeBase?
by Dreamer · in Torque Game Engine · 05/02/2005 (6:28 am) · 2 replies
Hello, I have needed to move a couple of stats up out of the datablock, so they are editable by the running game, they are namely MaxDamage and MaxEnergy.
I started by creating 2 new member variables mMaxDamage and mMaxEnergy, then 4 new functions and 4 new console methods. They are getMaxDamage, setMaxDamage, getMaxEnergy and setMaxEnergy.
To get the existing code to work properly I then did a global search and replace substituting mDatablock->maxDamage with mMaxDamage and mDatablock->maxEnergy with mMaxEnergy.
I compile w/o any errors and go run it.
Here is an example of my Console Log (1137 is Kork)
It would appear from the above that getMaxEnergy is refferencing the mMaxDamage rather than mMaxEnergy...
Look at the code below and you can clearly see that it isn't
As you can clearly see from the output it appears we are getting our wires crossed somewhere, but if so I'm not seeing it, and I've been staring at these functions for hours.
Any help would be greatly appreciated. Thanx!
*Update* Doh! My thinking was that the mMaxEnergy variable was somehow being tied to mMaxDamage... After posting this the bottom line caught my eye, in getMaxEnergy return object-getMaxDamage(); should prolly be return object->getMaxEnergy();
Oh well, just a lesson then, the hardest bugs to track down and fix, will almost always be the dumbest. :)
I started by creating 2 new member variables mMaxDamage and mMaxEnergy, then 4 new functions and 4 new console methods. They are getMaxDamage, setMaxDamage, getMaxEnergy and setMaxEnergy.
To get the existing code to work properly I then did a global search and replace substituting mDatablock->maxDamage with mMaxDamage and mDatablock->maxEnergy with mMaxEnergy.
I compile w/o any errors and go run it.
Here is an example of my Console Log (1137 is Kork)
% echo(1137.getMaxDamage()); 100 % 1137.setMaxDamage(1000); % echo(1137.getMaxDamage()); 1000 % echo(1137.getMaxEnergy()); 1000 % 1137.setMaxEnergy(100); % echo(1137.getMaxEnergy()); 1000 % 1137.setMaxDamage(500); % echo(1137.getMaxEnergy()); 500
It would appear from the above that getMaxEnergy is refferencing the mMaxDamage rather than mMaxEnergy...
Look at the code below and you can clearly see that it isn't
void ShapeBase::setMaxDamage(F32 maxdamage){
mMaxDamage = maxdamage;
updateDamageLevel();
}
F32 ShapeBase::getMaxDamage(){
return(mMaxDamage);
}
void ShapeBase::setMaxEnergy(F32 maxEnergy){
mMaxEnergy = maxEnergy;
//updateDamageLevel();
}
F32 ShapeBase::getMaxEnergy(){
return(mMaxEnergy);
}
ConsoleMethod( ShapeBase, setMaxDamage, void, 3, 3, "(F32 Max Damage)")
{
object->setMaxDamage(dAtof(argv[2]));
}
ConsoleMethod(ShapeBase, getMaxDamage, F32,2,2,"(no params returns F32)"){
return object->getMaxDamage();
}
ConsoleMethod( ShapeBase, setMaxEnergy, void, 3, 3, "(F32 MaxEnergy)")
{
object->setMaxEnergy(dAtof(argv[2]));
}
ConsoleMethod(ShapeBase, getMaxEnergy, F32,2,2,"(no params returns F32)"){
return object->getMaxDamage();
}As you can clearly see from the output it appears we are getting our wires crossed somewhere, but if so I'm not seeing it, and I've been staring at these functions for hours.
Any help would be greatly appreciated. Thanx!
*Update* Doh! My thinking was that the mMaxEnergy variable was somehow being tied to mMaxDamage... After posting this the bottom line caught my eye, in getMaxEnergy return object-getMaxDamage(); should prolly be return object->getMaxEnergy();
Oh well, just a lesson then, the hardest bugs to track down and fix, will almost always be the dumbest. :)
#2
and to sum it up,
go to ShapeBase.h and add around line 541 which should be public:
Then open ShapeBase.cc and add tot he end
then go to around line 606 where it says
Then if your using visual studio, do a global find and replace on mDatablock->maxDamage with mMaxDamage and mDatablock->maxEnergy with mMaxEnergy.
and she will compile and run ok on 1.4, btw, if you don't call the function to set max damage, the default max damage becomes 100... or whatever you set it to in the constructor... guess you could over ride them in the init persists..
Vince
02/03/2006 (8:29 pm)
Ok, since I already resurected this thread... the fix for the threading isShapeBase::ShapeBase()
{
mTypeMask |= ShapeBaseObjectType;
mMaxDamage = 100; //<--- Add this initialization
mMaxEnergy = 100;//<-- Add this initializationand to sum it up,
go to ShapeBase.h and add around line 541 which should be public:
void ShapeBase::setMaxDamage(F32 maxdamage); F32 ShapeBase::getMaxDamage(); void ShapeBase::setMaxEnergy(F32 maxEnergy); F32 ShapeBase::getMaxEnergy(); F32 mMaxDamage; F32 mMaxEnergy;
Then open ShapeBase.cc and add tot he end
void ShapeBase::setMaxDamage(F32 maxdamage){
mMaxDamage = maxdamage;
updateDamageLevel();
}
F32 ShapeBase::getMaxDamage(){
return(mMaxDamage);
}
void ShapeBase::setMaxEnergy(F32 maxEnergy){
mMaxEnergy = maxEnergy;
//updateDamageLevel();
}
F32 ShapeBase::getMaxEnergy(){
return(mMaxEnergy);
}
ConsoleMethod( ShapeBase, setMaxDamage, void, 3, 3, "(F32 Max Damage)")
{
object->setMaxDamage(dAtof(argv[2]));
}
ConsoleMethod(ShapeBase, getMaxDamage, F32,2,2,"(no params returns F32)"){
return object->getMaxDamage();
}
ConsoleMethod( ShapeBase, setMaxEnergy, void, 3, 3, "(F32 MaxEnergy)")
{
object->setMaxEnergy(dAtof(argv[2]));
}
ConsoleMethod(ShapeBase, getMaxEnergy, F32,2,2,"(no params returns F32)"){
return object->getMaxEnergy();
}then go to around line 606 where it says
ShapeBase::ShapeBase()
{
mTypeMask |= ShapeBaseObjectType;add right after itmMaxDamage = 100; //<--- Add this initialization mMaxEnergy = 100;//<-- Add this initialization
Then if your using visual studio, do a global find and replace on mDatablock->maxDamage with mMaxDamage and mDatablock->maxEnergy with mMaxEnergy.
and she will compile and run ok on 1.4, btw, if you don't call the function to set max damage, the default max damage becomes 100... or whatever you set it to in the constructor... guess you could over ride them in the init persists..
Vince
Torque Owner Vince Gee
Winter Leaf Entertainment
Vince