Author Topic: "Script-Syntax-Error" OP Updated: Server.CS simplified!  (Read 4427 times)

Trying to get an armor pack to work independently of this one (gravity cats military gear): http://forum.blockland.us/index.php?topic=107991.0
Each time I start up the server, a new syntax error comes along. I close blockland, then fix the error as stated in console, then re-load the server; however, this time I'm not sure what to do.

Edit(7/29/2014): Alright, so apparently the console log 'syntax error' was lying to me, and there must have been something wrong. I gave this code to a friend of mine and he fixed it, so I'll just leave this here for reference.

Non-Working Code
Code: [Select]
//########## Military Gears

exec("./MKI Suit.cs");

package DZ_MilGearPackage
{
  function servercmdDropTool(%this,%slot)
  {
    if(isobject(%this.player.tool[%slot]) && %this.player.tool[%slot].getname() $= "SOG_MKISuitItem")
      if(isobject(%this.player.getmountedimage(1)) && %this.player.getmountedimage(1).getname() $= "SOG_MKISuitMountedImage") { %this.player.schedule(5,unmountimage,1); }
    parent::servercmdDropTool(%this,%slot);
  }
   function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
  {
if(%obj.getMountedImage(1).getName() $= "SOG_MKISuitMountedImage")
{
    if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3*getWord(%obj.getScale(),2))
        %damage *= 0.5;
}
  };
      Parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
activatepackage(DZ_MilGearPackage);


Working Code
Code: [Select]
//########## Military Gears

exec("./MKI Suit.cs");

package DZ_MilGearPackage
{
function servercmdDropTool(%this, %slot)
{
%player = %this.getControllingObject();

if(isobject(%player.tool[%slot]) && %player.tool[%slot].getname() $= "SOG_MKISuitItem")
{
if(isobject(%player.getmountedimage(1)) && %player.getmountedimage(1).getname() $= "SOG_MKISuitMountedImage")
{
%player.schedule(5, unmountimage, 1);
}
}

parent::servercmdDropTool(%this, %slot);
}

function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
if(%obj.getMountedImage(1).getName() $= "SOG_MKISuitMountedImage")
{
if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3 * getWord(%obj.getScale(), 2))
{
%damage *= 0.5;
}
}

parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
}
};
activatepackage(DZ_MilGearPackage);
« Last Edit: July 29, 2014, 02:25:31 AM by Deadzone »

Your code is hard to read because your formatting is TERRIBLE. But it looks to me like you're missing a closing brace for Armor::damage.

I agree with jes - please clean up your format. What text editor are you using to code it? I recommend TorqueDev, as it will tell you what a lot of functions are and how to use them when you are coding, and tells you exactly what the syntax error is and where it is.
I can't actually view the .cs file, but it looks like you made a function, and then closed the package. Try closing the function then the package.

The if(%obj.getMountedImage(2).getName() $= "VisorCapMountedImage") has no opening bracket or closing bracket. You'll need to add those.

Don't forget () from getName lol
Whoops, fixed.
« Last Edit: July 27, 2014, 02:55:13 PM by Thorfin25 »

Don't forget () from getName lol

Actually under the if(isObject(%obj.getMountedImage(1))) you make the mistake of forgetting the opening/closing brackets a stuff ton. You can't do

Code: [Select]
if(%obj.getMountedImage(1).getName() $= "Infantry_PlateMountedImage")
  if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3*getWord(%obj.getScale(),2))
    %damage *= 0.85;
This won't work, it needs to be like
Code: [Select]
if(%obj.getMountedImage(1).getName() $= "Infantry_PlateMountedImage")
{
    if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3*getWord(%obj.getScale(),2))
        %damage *= 0.85;
}

I counted at least 54 instances of this mistake.
« Last Edit: July 27, 2014, 02:59:46 PM by Thorfin25 »

Code: [Select]
if(%obj.getMountedImage(1).getName() $= "Infantry_PlateMountedImage")
  if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3*getWord(%obj.getScale(),2))
    %damage *= 0.85;
This won't work, it needs to be like
Code: [Select]
if(%obj.getMountedImage(1).getName() $= "Infantry_PlateMountedImage")
{
    if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3*getWord(%obj.getScale(),2))
        %damage *= 0.85;
}
No it doen't, the first method is completely fine.

Though this code is very... questionable. You could simplify it a lot.

I counted at least 54 instances of this mistake.
Thorfin, that's perfectly valid code. Both of them are. I'm pretty sure that the actual problem is he used }; when he should've used }

You can chain link single-line if statements. For example:

Code: [Select]
%text = "this is a handicapped tree";
if( getWord( %text, 0 ) $= "this" )
    if( getWord( %text, 1 ) $= "is" )
        if( getWord( %text, 2 ) $= "a")
            if( getWord( %text, 3 ) $= "handicapped" )
                if( getWord( %text, 4 ) $= "tree" )
                    return 1;
                else
                    return 1; // it's still a handicapped tree
            else
                return 1;
        else
            return 1;
    else
        return 1;
else
    return 1;


What he did will work. You only need to put brackets if you want to do more than one line of functions after a conditional statement.


if(getWord(%string, 2) $= "blah")
    asdf();
    doStuff();

is invalid, but putting a bracket at the end will make it valid. You don't need do do that for chains of if statements - stacking them is fine.

Learned something new today then.

I agree with jes - please clean up your format. What text editor are you using to code it? I recommend TorqueDev, as it will tell you what a lot of functions are and how to use them when you are coding, and tells you exactly what the syntax error is and where it is.
I can't actually view the .cs file, but it looks like you made a function, and then closed the package. Try closing the function then the package.

I would but I'm just trying to get it to work, it's not even my code. I'll try some more things today and hopefully will find the problem...

I'll try some more things today and hopefully will find the problem...

It looks to me like you're missing a closing brace for Armor::damage.

Yeah, you forgot a closing bracket to close the function before you closed the package.

What he did will work. You only need to put brackets if you want to do more than one line of functions after a conditional statement.


if(getWord(%string, 2) $= "blah")
    asdf();
    doStuff();

is invalid, but putting a bracket at the end will make it valid. You don't need do do that for chains of if statements - stacking them is fine.
It's a logic error. It will still work. But weather the if statement is true or false it will run doStuff.