Blockland Forums > Modification Help

Chat Bot Problem

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

jes00:


--- Quote from: Placid on August 04, 2011, 08:52:57 AM ---i'm pretty sure switch lines can only be one line, but i might be wrong
case "Test":
    checkTest(%name);

... what do I put here?


function checkTest(%arg) {
    if(%arg $= $pref::Player::NetName)
        commandtoserver('messagesent',"Testing worked.");
}

i still might be wrong.


also, of course define the function outside of the other function.

--- End quote ---


AGlass0fMilk:

I think your problem is that you need a "break;" after every case in the switch statement. Try this:

--- 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 "Test":
                               if (%name $= "jes00")
                               {
                                    commandToServer('messageSent',"Test: Success!");
                                }
                               break;

                        case "Hi":
                              commandToServer('messageSent',"Hi");
                              break;

                        case "the muffin smells good!":
                                commandtoserver('messagesent',"It does indeed!");
                                break;

                        case "Goodbye":
                                commandtoserver('messagesent',"Goodbye.");
                                break;
                }
}

};
activatePackage(chatbot);

--- End code ---
Also, it is not necessary to put brackets around the single-line-if-statement, but I like to during testing, it helps you control program flow and keep mistakes from happening. This may not be the solution to your problem, but you should usually follow a case with a break; statement (depending on the application).

jes00:


--- Quote from: AGlass0fMilk on August 10, 2011, 12:46:52 PM ---I think your problem is that you need a "break;" after every case in the switch statement. Try this:
-script-
Also, it is not necessary to put brackets around the single-line-if-statement, but I like to during testing, it helps you control program flow and keep mistakes from happening. This may not be the solution to your problem, but you should usually follow a case with a break; statement (depending on the application).

--- End quote ---
Ty AGlassOfMilk! it works!!!

Blocker Ctgr:

how would you get it to say the words in a mini-game chat?

Placid:


--- Quote from: Blocker Ctgr on August 11, 2011, 02:14:57 PM ---how would you get it to say the words in a mini-game chat?

--- End quote ---
i don't see a use in this besides chatspamming, in which case it would be a pretty loving stupid bot.
however, the command is /teammessagesent and you should be able to figure it out from there.

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

Go to full version