Torque & Math question (simple)
by Stefan Lundmark · in Torque Game Engine · 04/17/2004 (5:36 pm) · 5 replies
I just downloaded Xaviers resource "Numeric Health Display".
Now, I'm trying to make it show a numeric value, that's MaxHealth - CurrentDamage. Not a percentage as it originally was.
I figured this one is easy to change but when I did, I got errors. For instance, I replaced;
int iHealth = 100 - control->getDamageLevel();
WITH
int iHealth = mHealth - control->getDamageLevel();
This change resulted in 2 errors, and I'm not even sure that's the way to go for the effect I mentioned above.
Any pointers for me?
Now, I'm trying to make it show a numeric value, that's MaxHealth - CurrentDamage. Not a percentage as it originally was.
int iHealth = 100 - control->getDamageLevel(); dSprintf( mHealth, 4, "%d", iHealth );
I figured this one is easy to change but when I did, I got errors. For instance, I replaced;
int iHealth = 100 - control->getDamageLevel();
WITH
int iHealth = mHealth - control->getDamageLevel();
This change resulted in 2 errors, and I'm not even sure that's the way to go for the effect I mentioned above.
Any pointers for me?
About the author
#2
Dan is prolly right.
tho I dont see why mHealth would be a string.
04/17/2004 (6:23 pm)
Without the code or the actual error it is just a guessing game.Dan is prolly right.
tho I dont see why mHealth would be a string.
#3
I'm really lost on this one.
Edit: Oh and Badguy, I thought this one was silly obvious.. I'll post the code :)
Here are the errors IF I put iHealth(int) to the string mentioned earlier.
04/18/2004 (2:43 am)
Oh, and how would I point it instead of integer it?I'm really lost on this one.
Edit: Oh and Badguy, I thought this one was silly obvious.. I'll post the code :)
void GuiHealthDisplayCtrl::onRender(Point2I offset, const RectI &updateRect)
{
// Must have a connection and player control object
GameConnection* conn = GameConnection::getServerConnection();
if (!conn)
return;
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & PlayerObjectType))
return;
int iHealth = 100 - control->getDamageLevel();
dSprintf( mHealth, 4, "%d", iHealth );
dglSetBitmapModulation( mProfile->mFontColor );
renderJustifiedText(offset, mBounds.extent, mHealth);
//render the child controls
renderChildControls(offset, updateRect);
}Here are the errors IF I put iHealth(int) to the string mentioned earlier.
Quote:
Compiling...
guiHealthDisplayCtrl.cc
C:\torque\engine\gui\guiHealthDisplayCtrl.cc(82) : error C2112: pointer subtraction requires integral or pointer operand
C:\torque\engine\gui\guiHealthDisplayCtrl.cc(82) : error C2440: 'initializing' : cannot convert from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
betatest.exe - 2 error(s), 0 warning(s)
#4
First, when you want to print an integer you first have to convert it to a string. That is what dSprintf is doing. I would bet that mHealth is NOT Max Health. mHealth appears to just be the string representation of the current health, which is used for displaying it in the gui. The m prefix is just part of the naming convention that means it is a class member variable, as opposed to a local variable or a global variable.
Look in the player datablock (or shapebase datablock) for a mMaxDamage member or something similar.
Peace
04/18/2004 (8:29 am)
I think the problem is that you are misunderstanding the naming convention being used.First, when you want to print an integer you first have to convert it to a string. That is what dSprintf is doing. I would bet that mHealth is NOT Max Health. mHealth appears to just be the string representation of the current health, which is used for displaying it in the gui. The m prefix is just part of the naming convention that means it is a class member variable, as opposed to a local variable or a global variable.
Look in the player datablock (or shapebase datablock) for a mMaxDamage member or something similar.
Peace
#5
int iHealth = (int)(control->getDataBlock()->maxDamage - control->getDamageLevel());
Or something to that effect. getDamageLevel probably returns the percent rather than the actual damage, so you might need to either modify setDamageLevel to store the actual damage, or calculate the actual damage from the percentage of the max damage in your GuiHealthDisplayCtrl::onRender
Peace
04/18/2004 (8:55 am)
What you probably want is something like:int iHealth = (int)(control->getDataBlock()->maxDamage - control->getDamageLevel());
Or something to that effect. getDamageLevel probably returns the percent rather than the actual damage, so you might need to either modify setDamageLevel to store the actual damage, or calculate the actual damage from the percentage of the max damage in your GuiHealthDisplayCtrl::onRender
Peace
Torque Owner Dan -
1 - mHealth is a pointer to a character string and not an int, therefore you can't do "mHealth - control->getDamageLevel();" Wrong types.
or
2 - mHealth is an int in which case dSprintf will error because the first parameter should be a pointer to a character.