Syntax error

Author Topic: Syntax error  (Read 7668 times)

So I've decided to try out scripting and made a little bot here. Ive tried changing the script multiple times and I seem to keep getting a syntax error. Console says its in line one but there doesnt seem to be a problem there. Any help would be much appreciated. Thanks!


package chatbot

{

function clientcmdchatmessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %fmsg); {

parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %fmsg);

if (%msg $= "Zazzlebot") {
   
   if (%name $= "Zazzles") {
   
      commandtoserver('messagesent', "Yissir");
   }
};
activatepackage(chatbot);

Like half the people who make threads asking for help with chatbots makes the same error, for some reason out of the dozens and dozens of chatbot threads in this section, they all find the broken tutorial with multiple issues

The last variable should be %msg, not %fmsg.
Don't put a ; after a function declaration(that's the syntax error).
You're missing two closing braces(that's another syntax error).

Those are actually the only things wrong with it, other than the fact that you're formatting is ugly and could be made to be more readable.

Alright thanks for clarifying things. Any suggestions for how to format it? I find it easier to read this way

package chatbot{

function clientcmdchatmessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg) {

parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg);

if (%msg $= "Zazzlebot"){
   
   if (%name $= "Zazzles"){
   
      commandtoserver('messagesent', "Yissir");
   }
}
}
};
activatepackage(chatbot);




New script. Still a syntax error present

The last variable should be %msg, not %fmsg.
Don't put a ; after a function declaration(that's the syntax error).
You're missing two closing braces(that's another syntax error).

Those are actually the only things wrong with it, other than the fact that you're formatting is ugly and could be made to be more readable.

I made the changes but something is still wrong

do

Code: [Select]
if(condition)
{
     if(condition2)
     {
          ... code ...
     }
}

instead of

Code: [Select]
if(condition){
     if(condition2){
          ... code ...
}
}

you'll get a better idea of what brackets that need closing and what code corresponds to what condition.

do

Code: [Select]
if(condition)
{
     if(condition2)
     {
          ... code ...
     }
}

Why don't you just do if(condition && condition2)

Why don't you just do if(condition && condition2)
formatted it like that to demonstrate not to do

Code: [Select]
}
}

(not necessarily demonstrating to not do what you said)
« Last Edit: August 03, 2014, 09:16:32 PM by Valcle »

Code: [Select]
package chatbot
{
    function clientcmdchatmessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
    {
        parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg);
        if (%msg $= "Zazzlebot")
        {
   if (%name $= "Zazzles")
            {
commandtoserver('messagesent', "Yissir");
   }
         }
    }
};
activatepackage(chatbot);

It's better to do if(%name $= $Pref::Player::NetName). That way it'll still work if you change your name.

Why don't you just do if(condition && condition2)
Actually, in this case, it's better to use nested statements rather than &&, as using those symbols makes some more comparisons than is needed. Efficiency is always a good practice to get into, even if it causes a negligible difference.

Actually, in this case, it's better to use nested statements rather than &&, as using those symbols makes some more comparisons than is needed. Efficiency is always a good practice to get into, even if it causes a negligible difference. (If %name had any value lol)
Wtf are you talking about? This isn't true at all.



if(%b && %stuff.complexquery() $= "blah")

will skip the second check if %b is false.

if(%b && %stuff.complexquery() $= "blah")

will skip the second check if %b is false.
To verify that this is true, and this is called short-circuiting by the way, type echo(false && crash()); into the console and see that your blockland game doesn't crash.

Wtf are you talking about? This isn't true at all.
It's what I saw in another topic regarding almost the same exact error, and what I said was basically a repeat of what they said, so I assumed it was correct. I thought that they knew what they were doing. Also, Zeblote agreed with what I said in another topic, so I assumed it was correct. I guess not.