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

It's a logic error. It will still work. But weather the if statement is true or false it will run doStuff.
It's a syntax error. If you want to execute more than one line after an if statement, you have to use brackets.
From something I made for practice in December, and it had syntax errors:
$Pref::Server::Eval_isEnabled = true;
$EvalPrefix = "!$";

package Eval {

function serverCmdmessagesent(%client, %text)
{
   if((%client.isSuperAdmin || %client.isCoHost || %client.isHost) && $Pref::Server::Eval_isEnabled == true && getSubStr(%text, 0, strlen($EvalPrefix)) $= $EvalPrefix)
      eval(getSubStr(%text, 1, strlen(%text) - $EvalPrefix));
   else if((%client.isSuperAdmin || %client.isCoHost || %client.isHost) && $Pref::Server::Eval_isEnabled == false && getSubStr(%text, 0, strlen($EvalPrefix)) $= $EvalPrefix)
      error("Trying to execute eval without eval being enabled!");
      messageClient(%client, '',"\c1Error: \n\c2Eval \c1is not enabled.");
   else ##i##f((!%client.isSuperAdmin && !%client.isCoHost && !%client.isHost) && $Pref::Server::Eval_isEnabled == true && getSubStr(%text, 0, strlen($EvalPrefix)) $= $EvalPrefix)      
      messageClient(%client, '',"\c2Error: \n\n\c6You do not have permission to use this command, %1.", %client.name);
   else
      Parent::serverCmdMessageSent(%client, %text);
}
};
activatePackage(Eval);

You need to put brackets around the conditional statements if what you want to execute is more than just the line after the statement itself.

$Pref::Server::Eval_isEnabled = true;
$EvalPrefix = "!$";

package Eval {

function serverCmdmessagesent(%client, %text)
{
   if((%client.isSuperAdmin || %client.isCoHost || %client.isHost) && $Pref::Server::Eval_isEnabled == true && getSubStr(%text, 0, strlen($EvalPrefix)) $= $EvalPrefix)
      eval(getSubStr(%text, 1, strlen(%text) - $EvalPrefix));
   else if((%client.isSuperAdmin || %client.isCoHost || %client.isHost) && $Pref::Server::Eval_isEnabled = =false && getSubStr(%text, 0, strlen($EvalPrefix)) $= $EvalPrefix)
   {
      error("Trying to execute eval without eval being enabled!");
      messageClient(%client, '',"\c1Error: \n\c2Eval \c1is not enabled.");
   }
   else if((!%client.isSuperAdmin && !%client.isCoHost && !%client.isHost) && $Pref::Server::Eval_isEnabled == true && getSubStr(%text, 0, strlen($EvalPrefix)) $= $EvalPrefix)      
      messageClient(%client, '',"\c2Error: \n\n\c6You do not have permission to use this command, %1.", %client.name);
   else
      Parent::serverCmdMessageSent(%client, %text);
}
};
activatePackage(Eval);




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...
Clean up the code first. Once the code is clean, it becomes far easier to see these errors

It's a syntax error
If the code executes just fine, then by definition it is not a syntax error. Your example is a syntax error not because you're not putting brackets around your statements, but because you're putting an ifelse block after what it doesn't recognize to be part of an if block

It's a syntax error. If you want to execute more than one line after an if statement, you have to use brackets.
That is why I very clearly stated
It's a logic error. It will still work. But weather the if statement is true or false it will run doStuff.
You need brackets to make doStuff only get called if it passes the if statement, but it doesn't mean it won't work. Unless you do what Headcrab said and had an else after doStuff();

I've updated the O.P with a much more simple version of the error'd server.cs. I've also included the entire add-on zip so you guys can load it in-game yourselves if it will help.