Author Topic: Chatbot syntax errors.  (Read 1786 times)

I was following this tutorial and found it kind of confusing. Nonetheless, I tried my best to do what it said and got this

Code: [Select]
package chatbot {
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg) {
parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
if (%msg $= "Testing") {
commandToServer('messageSent',"This was a triumph!");
}
};
activatePackage(chatbot);

I don't know a ton about scripting yet and I'm wondering what is causing the syntax errors.

You need a semicolon(;) after you parent.

Code: [Select]
parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);

Thanks. Now it says line 7 contains syntax errors though.

Fixed. Now it is saying line 8 is incorrect and contains errors.
« Last Edit: July 29, 2011, 11:41:32 PM by slimabob »

You've got the wrong number of brackets. The number of open and closed brackets in your script should be the same.

You've got the wrong number of brackets. The number of open and closed brackets in your script should be the same.

But if i have 5 brackets total, what do i do? Just add another one? And if so, does it matter where?

Code: [Select]
package chatbot {
  function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
    {
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);
    if (%msg $= "Testing") {
      commandToServer('messageSent',"This was a triumph!");
    }
  }
};
activatePackage(chatbot);

Awesome. I get it now, thanks a lot.

Okay I have another problem, now all my chat is red and it doesnt say who sent what message.

(Oh crap, double post)

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 $= "Testing") {
      commandToServer('messageSent',"This was a triumph!");
    }
  }
};
activatePackage(chatbot);

the fmsg arg was wrong in the parent

So if I wanted to add more commands, I think i would just do this (but im not sure):

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 $= "Testing") {
      commandToServer('messageSent',"This was a triumph!");
    if (%msg $= "Hi") {
      commandToServer('messageSent',"<color:e5e500>Mimic<color:ffffff>: Yo.");
      }
    }
  }
};
activatePackage(chatbot);

It's giving me syntax errors and I made sure that the brackets were equal.

the brackets are wrong

you misplaced the closing bracket on the first statement, i fixed it up a bit.

if it's only one line in the if statement, you can do without brackets.

i personally think else if is better in this case.
"if it isn't the last case, is it this?" is basically what it does


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 $= "Testing")
commandToServer('messageSent',"This was a triumph!");
else if(%msg $= "Hi")
commandToServer('messageSent',"Mimic: Yo.");
}

};
activatePackage(chatbot);

Alright, that worked but at line 25 i get a syntax error.

Alright, that worked but at line 25 i get a syntax error.
restart blockland


there is no line 25

restart blockland


there is no line 25

Yes there is. I sent you the code since I don't want people taking this script (however simple it may be).

UPDATE: it gives my a syntax error at line 25 but everything works until line 34.
« Last Edit: July 30, 2011, 01:50:43 AM by slimabob »

If you're going to add a bunch of commands, you'd be better of using a switch:

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
                switch$(%msg)
                {
                        case "Testing":
                               commandToServer('messageSent',"This was a triumph!");
                        case "Hi":
                              commandToServer('messageSent',"Mimic: Yo.");
                        case "Stuff":
                                commandtoserver('messagesent',"stuff");
                        case "More Stuff":
                                commandtoserver('messagesent',"More stuff");
                }
}

};
activatePackage(chatbot);