Author Topic: Syntax Error in Script  (Read 2341 times)

I recently just tried to turn this into a script, seemed simple. But when I make a server the Script does not load due to a syntax error.
Here is the script:
Code: [Select]
package TumbleOnFall
{
function Player::getVelocity(%this,%obj,%col,%pos,%speed)
{
%zVec = getWord(%obj.getVelocity(),2);
if(%zVec <= -20)
}
}
function tumble(%obj, %time)
{
   //do not tumble non-players
   if(!(%obj.getType() & $TypeMasks::PlayerObjectType))
      return;

   //do not tumble dead people
   if(%obj.getDamageLevel() >= 1.0)
      return;

//mount the object on a new deathvehicle for %time milliseconds
%currentVehicle = %obj.getObjectMount();
%client = %obj.client;

%newcar = new WheeledVehicle()
{
dataBlock = deathVehicle;
client = %client;
initialPosition = %posX @ " " @ %posY @ " " @ %posZ;
};
MissionCleanup.add(%newcar);
//%newcar = %client.tumbleVehicle;
%newcar.setVelocity("0 0 0");

if(!%newcar)
return;

//neutralize current velocity
%newcar.applyImpulse( %newcar.getPosition(), vectorScale(%newcar.getVelocity() * -1, %newcar.getDataBlock().mass) );

//error("player tumbling!");
%obj.canDismount = false;

if(%currentVehicle && (%currentVehicle.getDataBlock().getName() $= "skiVehicle") )
{
//%obj.client.setControlObject(%obj);
//match ski vehicle
//neutralize velocity first

%newcar.setTransform(%currentVehicle.getTransform());
%newcar.applyImpulse( %newcar.getPosition(), vectorScale(%currentVehicle.getVelocity(), %newcar.getDataBlock().mass) );
%newcar.mountObject(%obj, 0);

%currentVehicle.setTransform("0 0 -1000");
%currentVehicle.schedule(500, delete);
}
else
{
//match player
//error("transform = ",%obj.getTransform());
%newcar.setTransform(%obj.getTransform());
%newcar.applyImpulse( %newcar.getPosition(), vectorScale(%obj.getVelocity(), %newcar.getDataBlock().mass) );
//%newcar.setTransform(%obj.getTransform());

//%obj.setTransform("0 0 0 0 0 1 0");

%newcar.mountObject(%obj, 0);

//error("not skiing");
//error("transform = ",%obj.getTransform());
}

//definitely delete after 45 seconds
%newcar.schedule(45 * 1000, delete);

%newcar.schedule(2000, tumbleCheck);

%client.camera.setMode("Corpse",%obj);
%client.setControlObject(%client.camera);

//remove %player.istumbling after a we stop
//schedule(%time, %obj, stopTumble, %obj);


//%nextTumbleVehicle = new WheeledVehicle()
//{
// dataBlock = deathVehicle;
// client = %client;
// initialPosition = %posX @ " " @ %posY @ " " @ %posZ;
//};
//%obj.client.tumbleVehicle = %nextTumbleVehicle;
//%nextTumbleVehicle.setTransform("0 0 -90");



//%newcar.schedule(%time, unmountobject, %obj);
//%obj.schedule(%time, setcontrolobject, 0);
//%newcar.schedule(%time + 250, setTransform, "0 0 -90");
}
activatePackage(TumbleOnFall);
Here is the console log:
Code: [Select]
Loading Add-On: Script_TumbleOnFall (CRC:-480920754)
Add-Ons/Script_TumbleOnFall/TumbleOnFall.cs Line: 7 - Syntax error.
>>> Some error context, with ## on sides of error halt:
Package TumbleOnFall

{

^function Player::getVelocity(%this,%obj,%col,%pos,%speed)

^{

^%zVec = getWord(%obj.getVelocity(),2);

^if(%zVec <= -20)

^}##
##
}

function tumble(%obj, %time)

{

   //do not tumble non-players

   if(!(%obj.getType() & $TypeMasks::PlayerObjectType))

      return;



   //do not tumble dead people

   if(%obj.getDamageLevel() >= 1.0)

      return;



^//mount the object on a new deathvehicle for %time milliseconds
>>> Error report complete.

ADD-ON "Script_TumbleOnFall" CONTAINS SYNTAX ERRORS

The if statement in line 6.
You're not doing anything with it. Either remove it or add something after it.

Still getting a syntax error:
Code: [Select]
Loading Add-On: Script_TumbleOnFall (CRC:-1082501054)
Add-Ons/Script_TumbleOnFall/TumbleOnFall.cs Line: 7 - Syntax error.
>>> Some error context, with ## on sides of error halt:
ackage TumbleOnFall

{

^function Player::getVelocity(%this,%obj,%col,%pos,%speed)

^{

^%zVec = getWord(%obj.getVelocity(),2);

^(%zVec <= -20)

^}##
##
}

function tumble(%obj, %time)

{

   //do not tumble non-players

   if(!(%obj.getType() & $TypeMasks::PlayerObjectType))

      return;



   //do not tumble dead people

   if(%obj.getDamageLevel() >= 1.0)

      return;



^//mount the object on a new deathvehicle for %time milliseconds
>>> Error report complete.

ADD-ON "Script_TumbleOnFall" CONTAINS SYNTAX ERRORS

The error was not on line 6, it was Line 7, it is shown near the ##s.
« Last Edit: June 12, 2010, 02:10:35 PM by Audax »

Add a ; after the package

Code: [Select]
package f
{
     //stuff
}; //<-semicolon here


And it looks like you only remove the word if, remove that entire line.


I need that line of where the if statement was so it can check your velocity and tumble you.

Then add something after the if, and then post that part of the script. I was just saying what it looks like from the console file.

What are you trying to do, anyways?
« Last Edit: June 12, 2010, 02:17:16 PM by Headcrab Zombie »

There is something after 'if' though:
Code: [Select]
if(%zVec <= -20)

What I am trying to do is the script will check your velocity while you are falling. Once it reaches -20 or less on the Z-Axis (descending) the player will tumble as if crashing on the skis.

There is something after 'if' though:

Quote
package TumbleOnFall
{
   function Player::getVelocity(%this,%obj,%col,%pos,%speed)
   {
   %zVec = getWord(%obj.getVelocity(),2);
   if(%zVec <= -20)
        there's nothing here that will execute if the above if is true
   }
}


What I'd do is make a repeating function, first called when the server is started, that checks through everyone's velocity, and calls tumble if the velocity is high enough. You don't need to change anything in the tumble or getVelocity functions, just one looping function, and package one of the functions that is called when the server starts.

Quote from: Script
package TumbleOnFall
{
   function Player::getVelocity(%this,%obj,%col,%pos,%speed)
   {
   %zVec = getWord(%obj.getVelocity(),2);
   if(%zVec <= -20)
   }
}

The blank line was created in the console log, no idea why.

I'll try the looping function.

Wait, wouldn't it be better though to check the player's velocity while they are falling, instead of continuously checking?
« Last Edit: June 12, 2010, 02:37:45 PM by Audax »

As I said in your other topic, I don't believe there is an onFall function, so you'll have to continously check, unless someone can think of another way.

And you don't get what I mean about the if statement, look at the script that was posted on the first post, there is nothing on the line after the if that will be executed if the if evaluates to true.

Oh I see. What would I add though to call the tumble function if the player's velocity is less than or equal to -20?

if(getWord(%obj.getVelocity(),2) <= -20)
    tumble(%obj,2500);

Change %obj to whatever, of course.


Some people may find this script annoying though...

Now there is a Syntax error in 'function tumble'

Code: [Select]
Loading Add-On: Script_TumbleOnFall (CRC:1828132999)
Add-Ons/Script_TumbleOnFall/TumbleOnFall.cs Line: 13 - Syntax error.
>>> Some error context, with ## on sides of error halt:
ackage TumbleOnFall

{

^function Player::getVelocity(%this,%obj,%col,%pos,%speed)

^{

^%zVec = getWord(%obj.getVelocity(),2);

^if(%zVec <= -20)

^^{

^^if(getWord(%obj.getVelocity(),2) <= -20)

^^   tumble(%obj,2500);

^^}

^}

}

function ##t##umble(%obj, %time)

{

   //do not tumble non-players

   if(!(%obj.getType() & $TypeMasks::PlayerObjectType))

      return;



   //do not tumble dead people

   if(%obj.getDamageLevel() >= 1.0)

      return;



^//mount the object on a new deathvehicle for %time milliseconds
>>> Error report complete.

ADD-ON "Script_TumbleOnFall" CONTAINS SYNTAX ERRORS

Are there other parts of the deathVehicle code I need in the script?

Now there is a Syntax error in 'function tumble'

Loading Add-On: Script_TumbleOnFall (CRC:1828132999)
Add-Ons/Script_TumbleOnFall/TumbleOnFall.cs Line: 13 - Syntax error.
>>> Some error context, with ## on sides of error halt:
ackage TumbleOnFall

{

^function Player::getVelocity(%this,%obj,%col,%pos,%speed)

^{

^%zVec = getWord(%obj.getVelocity(),2);

^if(%zVec <= -20)

^^{

^^if(getWord(%obj.getVelocity(),2) <= -20)
^^{
^^   tumble(%obj,2500);
^^}
^^}

^}

}

function ##t##umble(%obj, %time)

{

   //do not tumble non-players

   if(!(%obj.getType() & $TypeMasks::PlayerObjectType))
{
      return;
}


   //do not tumble dead people

   if(%obj.getDamageLevel() >= 1.0)
{
      return;
}


^//mount the object on a new deathvehicle for %time milliseconds
>>> Error report complete.

ADD-ON "Script_TumbleOnFall" CONTAINS SYNTAX ERRORS

Are there other parts of the deathVehicle code I need in the script?

1. Pew is stupid, ignore him
2. there are two checks to see if the z velocity is less than -20
3. Player::getVelocity should be Player::onCollision, and should be parented
     Player::getVelocity makes no sense, it's not an event and is only called when other add-ons need to get the velocity.
4. tumble isn't closed? That might just be the snip of the whole code.