| Blockland Forums > Modification Help |
| So I made a chatbot... |
| (1/4) > >> |
| comedy101experiments:
A while back, I asked for help, and now I finally got it! But now I need help with an error. My chatbot doesn't even work anymore! :O Here is the code: --- Code: ---package chatbot { function clientCmdChatMessage( %cl, %voice, %pitch, %line, %pre, %name, %suf, %msg ) { parent::clientCmdChatMessage( %cl, %voice, %pitch, %line, %pre, %name, %suf, %msg ); %self = ( %name $= $Pref::Player::NetName ); switch$ ( %msg ) { case "comedyBot": if ( %self ) { commandToServer( 'messageSent', "comedyBot: Yes?" ); } case "afk": if ( %self ) { commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" ); } case "brb": if ( %self ) { commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" ); } case "Back": if ( %self ) { commandToServer( 'messageSent', "comedyBot: Welcome back!" ); } } } } }; activatePackage( "chatbot" ); --- End code --- |
| Port:
You cannot magically have sub-cases that use a secondary part of the string. And please, work on your indentation. In any case, you have an extra bracket near the end of the function. |
| SpreadsPlague:
your formatting is awful |
| LundoomGaming:
--- Code: ---removed --- End code --- Wait...this code doesn't even make sense. You first check if the msg is Comedybot, and then check if it IS Comedybot, is it also 'afk', 'brb', or 'back'. Tip: 1 word can't be two words |
| LundoomGaming:
Try this --- Code: ---package chatbot { function clientCmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg) { parent::clientCmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg); %self = (%name $= $Pref::Player::NetName); if(!%self) { return; } if(firstWord(%msg)$="Comedybot") saystuff(restWords(%msg)); } }; function saystuff(%msg) { switch(%msg) { if(%msg == "") { commandToServer( 'messageSent', "comedyBot: Yes?" ); } else if(%msg == "afk") { commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" ); } else if(%msg == "brb") { commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" ); } else if(%msg = "back") { commandToServer( 'messageSent', "comedyBot: Welcome back!" ); } } } activatePackage( "chatbot" ); --- End code --- |
| Navigation |
| Message Index |
| Next page |