Author Topic: Syntax error I don't understand?  (Read 1601 times)


what the hell
Code: [Select]
//Force trust by Setro, written on 9/3/2014
function servercmdforcetrust(%target, %client)
{
if(%client.isadmin)
{ messageClient(%client, '', "<color:ff0000>You are not an admin.");
return;
}
if(%client.name == %target.name)
{ announce("<color:00ff00>" SPC %client.name SPC "apparently doesn't trust himself!");
return;
}
%client.setMutualBrickGroupTrust(42358, %target.bl_id, 2);
echo(%client.name SPC "forced" @ %target.name"'s trust");
messageclient(%client, '', "<color:00ff00>You have forced<color:fff000>" @ %target.name"'s<color:00ff00> trust");
}
What's going on here? I don't understand.
I don't see any issues. Maybe I'm just missing something with my eyes?

Your whole script... is broken. The error it's complaining about is a missing @ in the line where you echo stuff. However, there are many more issues:

- The first argument of a servercmd is the client that used it, not the target
- You probably meant !%client.isadmin
- You have the name of the target from the servercmd, but you need to find the actual target first before you can use it
- You use $= to compare strings instead of ==, but in this case it would be better to simply compare the clients themselves
- setMutualBrickGroupTrust isn't called on %client
- You set it to trust a specific bl_id, not the one of the client
- You forgot @ 2 times after %target.name
- You forgot a couple spaces before and after names
- Your code formatting is horrible

I think I fixed all of these:


function servercmdforcetrust(%client, %tname)
{
   if(!%client.isadmin)
   {
      messageClient(%client, '', "<color:ff0000>You are not an admin.");
      return;
   }

   %target = findClientByName(%tname);

   if(!isObject(%target))
   {
      messageClient(%client, '', "<color:ff0000>That guy doesn't seem to exist...");
      return;
   }
   
   if(%client == %target)
   {
      messageAll('', "<color:00ff00>" @ %client.name @ " apparently doesn't trust himself!");
      return;
   }

   setMutualBrickGroupTrust(%client.bl_id, %target.bl_id, 2);

   echo(%client.name @ " forced " @ %target.name @ "'s trust");   
   messageclient(%client, '', "<color:00ff00>You have forced<color:fff000> " @ %target.name @ "<color:00ff00>'s trust");
}

« Last Edit: September 04, 2014, 02:34:18 PM by Zeblote »

Please give us the context part of the add-on also, we need the entire log.
But heres some things i noticed:
IDK if this is a prefrence, but i see people putting %client before %target.
You are doing a bad job at copying someone else's code, on line 4, it should be
Code: [Select]
if(!%client.isAdmin)
This is the only piece of code i'll spoon-feed you. The ! stands for NOT. So you're testing for if %client ISN'T admin, THEN execute return;

I'm not sure about this one whatsoever, but i'm pretty sure, that it should be
Code: [Select]
if(%client.name = %target.name) Could be both

This code is a loving mess, the indentation is stuff, your notifying functions are a mess. Is this a mashup of different mods? Echo, announce, messageclient etc. If you want to notify the one who enters the command, use %client.chatMessage("\C6White text here"); or messageClient(%client,'',"\C6White text here"); If you want to say something to all players, i suggest talk(text); for this. It would make the add-on seem actually decently made to the average blockhead, if the console talks as a error. I could nip-pick errors here all day, but i have to go. I'm guessing some other nearly decent coder will take over my job as a smart-ass.
As a side-note, i would like to apologize for being crude here, everyone was this bad at some point, keep on trying and keep on asking

EDIT: Looks like zeblote gave you a complete fix for everything, although he spoon-fed you pretty much the entire code -.- Do me a favor and actually re-write this and think everything over

echo(%client.name SPC "forced" @ %target.name"'s trust");

You forgot an @ after %target.name however it seems you forgot a %target = findclientbyname(%target); after the admin check, as you need the target's client object for this to work. And one more thing, on
if(%client.name == %target.name)
You should remember that == is for comparing numbers, and it's not likely that everybody's names are made up of numbers, you should instead use $= as that is for comparing strings.

I'm not sure about this one whatsoever, but i'm pretty sure, that it should be
Code: [Select]
if(%client.name = %target.name) Could be both
Using = with a conditional statement won't work and is incorrect.
==>%a = "this"; %b = "that"; echo(%a = %b);
that

= is used to set values, while == is used to compare between numerical values and $= is for strings.

Also, to make things shorter, Setro - you can sometimes put the return in front of the function you want to call. Instead of
if(!%client.isAdmin)
{
    messageClient(%client, '', "blah");
    return;
}
You can do this:

if(!%client.isAdmin)
    return messageClient(%client, '', "blah");

When only executing one line after a conditional statement, you don't need braces (also referred to as "brackets").
« Last Edit: September 04, 2014, 09:40:35 PM by Cruxeis »

]
Also, to make things shorter, Setro - you can sometimes put the return in front of the function you want to call. Instead of
if(!%client.isAdmin)
{
    messageClient(%client, '', "blah");
    return;
}
You can do this:

if(!%client.isAdmin)
    return messageClient(%client, '', "blah");

When only executing one line after a conditional statement, you don't need braces (also referred to as "brackets").
That's extremely bad practice, don't do it

Why? What's so bad about it?

Why? What's so bad about it?
Programming is not all about saving space. The function returns nothing useful, making it return that implies that it does something which it does not. It's bad in general.

Plus if you do that with engine defined void functions you'll get console spam errors along the lines of "call uses result of void function call"