Author Topic: Need some help with a script.  (Read 2672 times)

Using this tutorial, I've made a chatbot script here (WIP):

Code: [Select]
package chatbot {
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg) {
parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
if (%msg $= "123") {
if (%name $= "Game") {
commandToServer('messageSent',"ScriptWorking");
     }
}

What's wrong with it? The console says there's an error with line 4:

Code: [Select]
Client checking Add-On: Script_LockBot
Loading Add-On: Script_LockBot
Add-Ons/Script_LockBot/client.cs Line: 4 - Syntax error.
>>> Some error context, with ## on sides of error halt:
ackage chatbot {

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

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

^if ##(##%msg $= "123") {

^if (%name $= "Game") {

commandToServer('messageSent',"ScriptWorking");

     }

}
>>> Error report complete.

you forgot a ';' after the parent

also please format your code better, it's kinda hard to read code like that for some people

It may be just the formatting that's throwing me off, but it also looks like you didn't close the package. Also remember that packages have to be closed the same way that data blocks and objects do "};" notice that the semicolon after the closing bracket is required.

Using this tutorial, I've made a chatbot script here (WIP):

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
{
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
    if (%msg $= "123")
    {
        if (%name $= "Game")
        {
             commandToServer('messageSent',"ScriptWorking");
     }
}

If we break this bad boy down so it's easier on the eyes, you have four opening brackets, and only two closing. You need to toss in the other missing bracket after your last if statement and

it also looks like you didn't close the package.

Another thing also to do with chat bots is check the name first, then the message. So you can do a chain if/else line.

You will also have to close and activate the package for it to actually work.

You need a semicolon after the parent call, as well

Also, use NHM_Type::send if you want yourself to be the only one able to interact with it
« Last Edit: July 06, 2014, 10:28:34 AM by Headcrab Zombie »

also something to note is that chatbots are generally frowned upon

So should it come out as:

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
{
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);
    if (%msg $= "123")
    {
        if (%name $= "Game")
        {
             commandToServer('messageSent',"ScriptWorking");
     }
};
activatePackage(chatbot);

?

So should it come out as:

Code: [Select]
snip

?
no, you're missing a bracket there

it should be
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
{
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);
    if (%msg $= "123")
    {
        if (%name $= "Game")
        {
             commandToServer('messageSent',"ScriptWorking");
        }
     }
};
activatePackage(chatbot);

no, you're missing a bracket there

it should be
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
{
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);
    if (%msg $= "123")
    {
        if (%name $= "Game")
        {
             commandToServer('messageSent',"ScriptWorking");
        }
     }
};
activatePackage(chatbot);
You don't need two brackets for one line after an if statement.
Change

if(%name $= "Game")
{
    commandToServer('messageSent', "ScriptWorking");
}

to

if(%name $= "Game")
    commandToServer('messageSent', "ScriptWorking");

Syntax errors line 12
Code: [Select]
};##
##
activatePackage(chatbot);
Current Code:
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
{
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);
    if (%msg $= "123")
    {
        if (%name $= "Game")
             commandToServer('messageSent',"ScriptWorking");
     }
};
activatePackage(chatbot);

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg)
{
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);
    if (%msg $= "123" && %name $= "Game")
    {
             commandToServer('messageSent',"ScriptWorking");
    }
}
};
activatePackage(chatbot);
you forgot a closing bracket for the function too

you forgot a closing bracket for the function too
Now I get syntax errors at:
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);##
##
{
    parent::clientCmdChatMessage(%a,%b,%c,%msg,%cp,%name,%cs,%msg);
    if (%msg $= "123")
    {
        if (%name $= "Game")
             commandToServer('messageSent',"ScriptWorking");
     }
};
activatePackage(chatbot);

Get rid of the first ;

Get rid of the first ;
Doing that gives me syntax errors towards the end

EDIT:

The Error:
};##
##
activatePackage(chatbot);
« Last Edit: July 06, 2014, 12:33:33 PM by TB2 »