Author Topic: Syntax error: Projectile Changing function  (Read 691 times)

You may be able to tell, but this function is supposed to change the projectile of a weapon when the player's health is full. Ran into a syntax error I couldnt make sense of. Help?

Code: [Select]
function MasterImage::OnFire(%client, %obj,%slot) //%otherargs means the other client sided arguements needed for this specific edit.
{
%health = mFloor($MaxHealth - %client.player.getDamageLevel() + 0.5) //This gets the clients Nice little Health!
if(!%health = 100) //If the Persons health is at max
{
%p = new (MasterProjectile)()
{
dataBlock = MasterProjectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}

else
{
%p = new (MasterProjectileFull)()
{
dataBlock = MasterProjectileFull;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
}
I get a syntax error for some reason:
Quote from: Code
Loading Add-On: Weapon_TSP
Add-Ons/Weapon_TSP/Master Sword [TP]/server.cs Line: 215 - Syntax error.
>>> Some error context, with ## on sides of error halt:
function MasterImage::OnFire(%client, %obj,%slot) //%otherargs means the other client sided arguements needed for this specific edit.

{

^%health = mFloor($MaxHealth - %client.player.getDamageLevel() + 0.5) //This gets the clients Nice little Health!

^if(##%##health = 100) //If the Persons health is at max

^{

^^%p = new (MasterProjectile)()

^^{

^^^dataBlock = MasterProjectile;

^^^initialVelocity = %velocity;

^^^initialPosition = %obj.getMuzzlePoint(%slot);

^^^sourceObject = %obj;

^^^sourceSlot = %slot;
>>> Error report complete.

ADD-ON "Weapon_TSP" CONTAINS SYNTAX ERRORS
D:?

« Last Edit: December 04, 2010, 02:10:59 PM by takato14 »

instead of
%health = mFloor($MaxHealth - %client.player.getDamageLevel() + 0.5) //This gets the clients Nice little Health!
use
%health = mFloor($MaxHealth - %client.player.getDamageLevel() + 0.5); //This gets the clients Nice little Health!

you were missing a ;

Thank you. I checked for semicolons but I guess I missed one. xP

Thats no longer an error, but now its doing this:

x_x

Why did you add an extra } there after the Mission cleanup?

Also change
if(!%health = 100)
to
if(%health != 100)

and even if you were not using a !, it would be ==, not =.

Why did you add an extra } there after the Mission cleanup?

Also change
if(!%health = 100)
to
if(%health != 100)

and even if you were not using a !, it would be ==, not =.
So that explains why its still not working even after I stopped the syntax errors. Thank you.

Cleaned-up code:
Code: [Select]
function masterImage::onFire(%this, %obj, %slot) {
   if(%obj.getDamageLevel() > 0) {
      %p = new Projectile(MasterProjectile) {
            datablock = MasterProjectile;
            initialVelocity = %velocity;
            initialPosition = %obj.getMuzzlePoint(%slot);
            sourceObject = %obj;
            sourceSlot = %slot;
            client = %obj.client;
      };
      MissionCleanup.add(%p);
   }
   else {
      %p = new Projectile(MasterProjectileFull) {
            datablock = MasterProjectileFull;
            initialVelocity = %velocity;
            initialPosition = %obj.getMuzzlePoint(%slot);
            sourceObject = %obj;
            sourceSlot = %slot;
            client = %obj.client;
      };
      MissionCleanup.add(%p);
   }
}
« Last Edit: January 13, 2011, 08:42:18 AM by Bauklotz »

Cleaned-up code:
Code: [Select]
function masterImage::onFire(%this, %obj, %slot) {
   if(%obj.getDamageLevel() > 0) {
      %p = new Projectile(MasterProjectile) {
            datablock = MasterProjectile;
            initialVelocity = %velocity;
            initialPosition = %obj.getMuzzlePoint(%slot);
            sourceObject = %obj;
            sourceSlot = %slot;
            client = %obj.client;
      };
      MissionCleanup.add(%p);
   }
   else {
      %p = new Projectile(MasterProjectileFull) {
            datablock = MasterProjectileFull;
            initialVelocity = %velocity;
            initialPosition = %obj.getMuzzlePoint(%slot);
            sourceObject = %obj;
            sourceSlot = %slot;
            client = %obj.client;
      };
      MissionCleanup.add(%p);
   }
}
Erm, that works, but it screws up the projectile lifetime...

Like, it spawns the projectiles, but they vanish before they can hit anything. I spawned the projectiles manually (set the gun to fire them instead) and they work. Whats going on?

Uber-huge mofo pagebump.