Blockland Forums > Modification Help

Chatbot syntax errors.

Pages: << < (3/6) > >>

otto-san:

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: ---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);
--- End code ---


slimabob:

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

otto-san:


--- Quote from: slimabob on July 30, 2011, 01:34:04 AM ---Alright, that worked but at line 25 i get a syntax error.

--- End quote ---
restart blockland


there is no line 25

slimabob:


--- Quote from: otto-san on July 30, 2011, 01:37:10 AM ---restart blockland


there is no line 25

--- End quote ---

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.

Headcrab Zombie:

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


--- Code: ---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);
--- End code ---


Pages: << < (3/6) > >>

Go to full version