chatbot error

Author Topic: chatbot error  (Read 3133 times)

Code: [Select]
//by ikares
//forget off, you can't touch me <3

package chatty {
    function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg) {
        parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg);
    }
};
activatePackage(chatty)

if (%msg $= "hi chatty") {
    if(%name = %client)
        commandToServer('messageSent',"chatty: Hey, friend! :)");
    }
}

help pls

when i type hi chatty in chat it displays nothing. i used a chatbot tutorial from 2011, and also, if it helps, i'm using codeblocks to type my script.

There are a couple things I noticed here.
You put the if code (where you check the name and message) outside of the function and package itself.
You're checking if %msg is "hi chatty" but you aren't actually using it, the message variable looks to be called %fmsg instead, same goes for the %client.
Also this is just personal opinion but it's easier to read if like this

package chatty
{
    function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg)
    {
            parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg);
    }
};
activatePackage(chatty)

if (%msg $= "hi chatty")
{
    if(%name = %client)
        commandToServer('messageSent',"chatty: Hey, friend! :)");
    }
}


Also for the if name check you've placed a closing bracket, but never placed an open one.

There are a couple things I noticed here.
You put the if code (where you check the name and message) outside of the function and package itself.
You're checking if %msg is "hi chatty" but you aren't actually using it, the message variable looks to be called %fmsg instead, same goes for the %client.
Also this is just personal opinion but it's easier to read if like this

-snip-


Also for the if name check you've placed a closing bracket, but never placed an open one.
Alright, I'm cleaning it up now, and I'll test..

Erm.. the issue is that your code isn't inside a function. It just kinda runs once when the file is executed, and since %msg is undefined it will never be "hi chatty". It isn't ran any time any time anyone talks.

You need to move that code into your clientCmdChatMessage function.

The second issue is that you're using the variable name %fmsg twice in clientCmdChatMessage. Only the first one is supposed to be called %fmsg, because it is the full message. The last one is just %msg, and that's the variable you're gonna wanna check against "hi chatty".

The third issue is that there's no opening bracket after if(%name = %client) yet there is a closing one. You can either have both an opening and a closing bracket, or neither. No half way.

The fourth issue is that == is how you check two numbers are equal, not =. = only assigns.

Finally, the fifth issue is that %client isn't defined anywhere. It'll equal zero, so %name will never equal it.
« Last Edit: August 01, 2014, 09:24:23 PM by $trinick »

Alright, I edited my script.
Will this work?

Code: [Select]
//by ikares
//forget off, you can't touch me <3

package chatty
{
    function clientCmdChatMessage(%client,%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
}
       
    {
        parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
        }
            {
                if (%msg $= "hi chatty")
                        if(%name = %client)
                commandToServer('messageSent',"chatty: Hey, friend! :)");
            }
activatePackage(chatty)
also i'm still learning guys

The second issue is that you're using the variable name %fmsg twice in clientCmdChatMessage. Only the first one is supposed to be called %fmsg, because it is the full message. The last one is just %msg, and that's the variable you're gonna wanna check against "hi chatty"
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


You opened the package, said a function and then closed. Although that wasn't in the right spot remember that all packages close with }; instead of just }. You need to put all of the functions you are going to use inside the package, then close and activate it.
You forgot a semi-colon at the end of you activating the package.
You don't need to use an opening bracket after parenting something, and you can make your two if statements into one by using &&.


 if (%msg $= "hi chatty")
                        if(%name = %client)

Can be simplified into

if(%msg $= "hi chatty" && %name = %client)


Also I forgot to mention that if you are going to parent something make sure you are using the same variables as the function you are using. You randomly added in %client to the function but aren't parenting with it.
« Last Edit: August 01, 2014, 11:03:21 PM by Crøwn »

I'm pretty sure having if(%name $= %client) will never work like that anyways.
A better way to create a chat bot is also to make it purely client, instead of allowing it for everybody to use. So you should start off with:
Code: [Select]
package(chatty)
{
function NMH_Type::Send(%this)
{
    parent::send(%this);
    %msg=%this.getValue();
    if(%msg $= "blah")
    {
        //dostuff
    }
    %this.setValue="";
}
};
activatepackage(chatty);
« Last Edit: August 02, 2014, 12:55:55 PM by Thorfin25 »

I'm pretty sure having if(%name $= %client) will never work like that anyways.
A better way to create a chat bot is also to make it purely client, instead of allowing it for everybody to use. So you should start off with:
Code: [Select]
package(chatty)
{
function NMH_Type::Send(%this)
{
    parent::send(%this);
    %msg=%this.getValue;
    if(%msg $= "blah")
    {
        //dostuff
    }
    %this.setValue="";
}
};
activatepackage(chatty);
what exactly is Nmh_Type?

what exactly is Nmh_Type?

It's the object for the chatbox you type into in-game. The send function, well, is called when you send it or hit enter.

You opened the package, said a function and then closed. Although that wasn't in the right spot remember that all packages close with }; instead of just }. You need to put all of the functions you are going to use inside the package, then close and activate it.
You forgot a semi-colon at the end of you activating the package.
You don't need to use an opening bracket after parenting something, and you can make your two if statements into one by using &&.


 if (%msg $= "hi chatty")
                        if(%name = %client)

Can be simplified into

if(%msg $= "hi chatty" && %name = %client)


Also I forgot to mention that if you are going to parent something make sure you are using the same variables as the function you are using. You randomly added in %client to the function but aren't parenting with it.
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)
« Last Edit: August 02, 2014, 06:27:49 AM by Cruxeis »

I'm pretty sure having if(%name $= %client) will never work like that anyways.
A better way to create a chat bot is also to make it purely client, instead of allowing it for everybody to use. So you should start off with:
Code: [Select]
package(chatty)
{
function NMH_Type::Send(%this)
{
    parent::send(%this);
    %msg=%this.getValue;
    if(%msg $= "blah")
    {
        //dostuff
    }
    %this.setValue="";
}
};
activatepackage(chatty);
Thorfin. Learn what you're doing before you help people. Or you'll just make things worse. You forgot the () after getValue. setValue is a method, not a variable. And why even set the value to blank if you've already parented it?

I use setValue like that to get rid of the box afterwards, because for some reason without that at the end it never went away for me. And oh no, I forgot (), a simple little mistake anybody can make.

I use setValue like that to get rid of the box afterwards, because for some reason without that at the end it never went away for me. And oh no, I forgot (), a simple little mistake anybody can make.
You should try not to make such mistakes when you're trying to teach someone else.

It's not like I do that on purpose, and besides, nobody else suggested NMH_Type yet.