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

Your brackets don't match up. Count your opening and closing brackets and see if you notice the problem.

After looking at the script, I ended up with no syntax errors and this:
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%cp,%name,%cs,%msg);
if (%msg $= "123")
{
if (%name $= "Game")
commandToServer('messageSent',"ScriptWorking");
}
}
};
activatePackage(chatbot);
But now "clientCmdChatMessage" won't work.

quick edit, I removed the ifName function.

This isn't the problem, but as someone else said, check name first, then check message, otherwise your going to have to check name multiple names if you want multiple messages to respond to

This isn't the problem, but as someone else said, check name first, then check message, otherwise your going to have to check name multiple names if you want multiple messages to respond to
Or if you don't want to check for it being your name at all, just use NMH_Type::Send(%this) and then have it do %this.getValue();.

Any ideas on fixing the script?

Code: [Select]
package Chatbot
{
function NMH_Type::Send(%this)
{
    %Msg=%this.getvalue();
    if(%msg$="123")
    {
        commandToServer('messageSent',"trolol");
    }
    %this.setValue=("");
    Parent::Send(%this);
}
};
activatePackage(Chatbot);

Of you can use getWord(%msg,#) in your if statements so something like
Code: [Select]
if(getWord(%msg,0)$="bot")
{
    if(getWord(%msg,1)$="something"
    {
        something();
    }
}
That'll check if you say Bot Something it ignores caps too btw

Code: [Select]
package Chatbot
{
function NMH_Type::Send(%this)
{
    %Msg=%this.getvalue();
    if(%msg$="123")
    {
        commandToServer('messageSent',"trolol");
    }
    %this.setValue=("");
    Parent::Send(%this);
}
};
activatePackage(Chatbot);

Of you can use getWord(%msg,#) in your if statements so something like
Code: [Select]
if(getWord(%msg,0)$="bot")
{
    if(getWord(%msg,1)$="something"
    {
        something();
    }
}
That'll check if you say Bot Something it ignores caps too btw
You can also use getWords(%string, %start, %end); instead of using a bunch of single getWord if statements.
Also, I think NMH is what happens after you push enter while chatting, so, Thorfin, I think you are checking an empty string. (Not entirely sure, but I think so)I think you should call the parent first.
« Last Edit: July 06, 2014, 07:47:37 PM by Ninjaman 4 »

Thorfin, I think you are checking an empty string. (Not entirely sure, but I think so)I think you should call the parent first.

Nah it's not an empty string.

Also, I think NMH is what happens after you push enter while chatting, so, Thorfin, I think you are checking an empty string. (Not entirely sure, but I think so)I think you should call the parent first.
No, he's doing it right, at least in that aspect.
It does contain a few errors, though: case mismatch (although it doesn't matter in Torque, it still looks bad) on lines 5 and 6, an unneeded = on line 10 (actually that line in general is unwanted as that will erase the chat line before its sent), and a missing right paranthesis on line 1 in the second snippet
« Last Edit: July 06, 2014, 08:55:34 PM by Headcrab Zombie »

I found if I don't set %this back to nothing when it parents, that the chat message doesn't send, and it still leaves it typed in like you're going to say it. But the functions will still go through.

Is there any way to ignore text after the message? This is so I don't have 15 lines of different punctuation.

...I don't understand what you mean
There is no "text" after the message, just use the message variable

Code: [Select]
if(getWord(%msg,0)$="bot")
{
    if(getWord(%msg,1)$="something"
    {
        something();
    }
}
That'll check if you say Bot Something it ignores caps too btw

If you do something like this it'll activate if you say Bot something and will ignore whatever else you say. So you could say Bot something heil Riddler and it'll still work.

If you do something like this it'll activate if you say Bot something and will ignore whatever else you say. So you could say Bot something heil Riddler and it'll still work.
No, it wouldn't work, you forgot a closing parenthesis on line 3.