Game Development Community

Bug: function ShapeBase::setDamageDt

by Michael Cozzolino · in Torque Game Engine · 03/17/2005 (10:17 am) · 0 replies

I don't know if anyone already noticed this but here it goes.

Torque 1.3

Currently the code only damages the player when first entering the function.
The applied damage over time is not working because it is trying to reference %obj which does not exist.

function ShapeBase::setDamageDt(%this, %damageAmount, %damageType)
{
   // This function is used to apply damage over time.  The damage
   // is applied at a fixed rate (50 ms).  Damage could be applied
   // over time using the built in ShapBase C++ repair functions
   // (using a neg. repair), but this has the advantage of going
   // through the normal script channels.
   if (%obj.getState() !$= "Dead") {
      %this.damage(0, "0 0 0", %damageAmount, %damageType);
      %obj.damageSchedule = %obj.schedule(50, "setDamageDt", %damageAmount, %damageType);
   }
   else
      %obj.damageSchedule = "";
}


Should be:

function ShapeBase::setDamageDt(%this, %damageAmount, %damageType)
{
   // This function is used to apply damage over time.  The damage
   // is applied at a fixed rate (50 ms).  Damage could be applied
   // over time using the built in ShapBase C++ repair functions
   // (using a neg. repair), but this has the advantage of going
   // through the normal script channels.
   if ([b]%this[/b].getState() !$= "Dead") {
      %this.damage(0, "0 0 0", %damageAmount, %damageType);
      [b]%this[/b].damageSchedule = [b]%this[/b].schedule(50, "setDamageDt", %damageAmount, %damageType);
   }
   else
      [b]%this[/b].damageSchedule = "";
}


Also the clearing function is wrong.

function ShapeBase::clearDamageDt(%this)
{
   if (%obj.damageSchedule !$= "") {
      cancel(%obj.damageSchedule);
      %obj.damageSchedule = "";
   }
}

Should be:

function ShapeBase::clearDamageDt(%this)
{
   if ([b]%this[/b].damageSchedule !$= "") {
      cancel([b]%this[/b].damageSchedule);
      [b]%this[/b].damageSchedule = "";
   }
}

About the author

Indie Developer in the Albany NY area. iOS, PC, Mac OSX development. http://itunes.apple.com/us/artist/michael-cozzolino/id367780489