Script confusion
by Steve D · in Torque Game Engine · 01/30/2007 (7:35 pm) · 4 replies
Hi all, I'm a little confused at how data values are retained and passed on. Here is my simple player datablock -
datablock PlayerData(PlayerBody)
{
renderFirstPerson = false;
shapeFile = "~/data/shapes/player/player.dts";
runSurfaceAngle = "40";
maxdamage = 200;
};
Now here is my trigger -
function newtrigger::onentertrigger(%this, %trigger, %obj)
{
%obj.applydamage(50);
echo("damage level is", %obj.getdamagelevel());
}
The problem is the maxdamage of this obj is null so I'm really confused since I gave it a max damage value (even though the default is 100). Obviously I'm missing something here, can anyone shed some light?
datablock PlayerData(PlayerBody)
{
renderFirstPerson = false;
shapeFile = "~/data/shapes/player/player.dts";
runSurfaceAngle = "40";
maxdamage = 200;
};
Now here is my trigger -
function newtrigger::onentertrigger(%this, %trigger, %obj)
{
%obj.applydamage(50);
echo("damage level is", %obj.getdamagelevel());
}
The problem is the maxdamage of this obj is null so I'm really confused since I gave it a max damage value (even though the default is 100). Obviously I'm missing something here, can anyone shed some light?
#2
01/30/2007 (8:01 pm)
I tried that I'm still having the same result - the obj's damage level is null so getdamagelevel comes back as 50.
#3
You're confused about what getDamageLevel returns.
getDamageLevel returns how much damage a player has sustained and not their maxDamage level. It does not take into account the maxDamageLevel (in your case 200) defined in the player datablock. So getDamageLevel cannot be used on its own to calculate a player's current level / percentage of health. Remember, it only returns how many units of damage your player has had inflicted.
The reason it returns 50 in your case is because you apply 50 damage upon entering the trigger. So maxDamage is not null as you stated.
If you want to return the maxDamage value as defined in the player datablock you need to use:
If you wanted to calculate the player's current health level you could use:
You could also use this to express it as a percentage:
Does all that make sense?
01/30/2007 (10:06 pm)
I think I see the problem now. You're confused about what getDamageLevel returns.
getDamageLevel returns how much damage a player has sustained and not their maxDamage level. It does not take into account the maxDamageLevel (in your case 200) defined in the player datablock. So getDamageLevel cannot be used on its own to calculate a player's current level / percentage of health. Remember, it only returns how many units of damage your player has had inflicted.
The reason it returns 50 in your case is because you apply 50 damage upon entering the trigger. So maxDamage is not null as you stated.
If you want to return the maxDamage value as defined in the player datablock you need to use:
%maxDamage = %obj.getDatablock().maxDamage;
If you wanted to calculate the player's current health level you could use:
%maxDamage = %obj.getDatablock().maxDamage; %damageLevel = %obj.getDamageLevel(); %curHealth = %maxDamage - %damageLevel; %curHealth = mceil(%curHealth);
You could also use this to express it as a percentage:
%damagePercent = %obj.getDamagePercent(); %curDamagePercent = getSubStr(%damagePercent, 0, 4);
Does all that make sense?
#4
01/30/2007 (10:27 pm)
Thanks Tim, the getdatablock() is the piece I was missing. I was also trying to output a few other variables from the original player datablock and they were coming up blank as well. After burning a few brain cells and before reading your post I figured I wasn't pulling the data from the datablock itself and that's where I was going wrong. Anyway thanks again!
Torque Owner Tim Heldna
Try this:
echo("damage level is " @ %obj.getDamageLevel());