Author Topic: Simple arithmetic help in torque  (Read 1009 times)

The way this weapon is supposed to work is that every time this script onBuffer is called, a variable increases in value. That variable directly affects bullet deviation in a very simple manner. Here are the weapon's scripts:


function BusterCarbineImage::onReady(%this,%obj,%slot)
{
   %obj.RecoilCount = 0;
}

function BusterCarbineImage::onFire(%this,%obj,%slot,%recoil)
{
   serverPlay3D(gunshot1Sound, %obj.getPosition());
   %obj.playthread(0, plant);

   %recoil = %obj.RecoilCount;
   %spread = 0.1;
   %vector = %obj.getMuzzleVector(%slot);
   %vector = VectorScale(%vector, 130);
   %x = 0;
   %y = (%recoil * %spread);
   %z = 0;
   %mat = MatrixCreateFromEuler(%x SPC %y SPC %z);
   %velocity = MatrixMulVector(%mat, %vector);
   %p = new projectile()
   {
      dataBlock = gunProjectile;
      initialVelocity = %velocity;
      initialPosition = %obj.getMuzzlePoint(%slot);
      sourceObject = %obj;
      sourceSlot = %slot;
      client = %obj.client;
   };
   missionCleanup.add(%p);
   return  %p;
}

function BusterCarbineImage::onBuffer(%this,%obj,%slot,%recoil)
{
   %obj.playThread(0, root);
   if(%obj.RecoilCount >= 1)
   {
      %obj.RecoilCount = 1;
   }
   else
   {
      %obj.RecoilCount += .25;
   }
}


A syntax error occurs here (from console log):

function BusterCarbineImage::onBuffer(%this,%obj,%slot,%recoil)

{

^%obj.playThread(0, root);

^if(%obj.RecoilCount >= 1)

^{

^^%obj.RecoilCount = 1;

^}

^else

^{

^^%obj.RecoilCount += .##2##5;

^}

}
>>> Error report complete.

ADD-ON "Weapon_BusterCarbine" CONTAINS SYNTAX ERRORS


What's actually wrong with the code? Other pointers would be appreciated as well. Thank you.

try 0.25 or ".25" instead of .25?

and cloudflare blocked me from posting this lol

That fixed the error, thank you. I actually remember that being a problem before when it came to timeout values in sequences and I guess I'd forgotten.

It creates a really weird effect though. The bullets deviate in a straight line, like I'd intended, but the direction seems to depend on where I'm facing. It can deviate downwards, upwards, and I'm pretty sure I even saw diagonal spread. I wanted it to only be upwards. Any ideas?
« Last Edit: July 05, 2015, 04:25:44 PM by Gumba Jonny »

Z is up and down, not Y.

that's really strange that it would be going down/up when it should be going to one of the sides, based off of your code