Author Topic: Packaging clientcmdchatmessage crashes blockland  (Read 2089 times)

package Chatbot
{
    function clientCmdChatMessage( %cl, %voice, %pitch, %line, %pre, %name, %suf, %msg )
    {
   callinganonexistantfunctionto findwhereblocklandiscrashing();
   dochatbotchatstuff(%msg);
   return Parent::clientcmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg);
    }
};
activatePackage(chatbot);
function DoChatBotChatstuff(%msg)
{
   NONEXISTANTFNUCTIONGYHHAILRid dler();
   if(chatbotbios(%msg) $= "")
   return;
   commandToServer('messageSent', chatbotBIOS(%msg));
}


chatbotbios is a working function and is not the source of the issue.

package Chatbot
{
    function clientCmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg)
    {
   callinganonexistantfunctionto findwhereblocklandiscrashing();
   dochatbotchatstuff(%msg);
   return Parent::clientcmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg);
    }
};
activatePackage(chatbot);


chatbotbios is a working function and is not the source of the issue.

You don't return the parent?
Also it's %a,%b,%c,%cp,%name,%cs,%msg so your %line gets in the way.

chatbotbios is a working function and is not the source of the issue.
How do you know this? It would be better if you posted your full code, so we could see exactly what wrong.
-coding snips-
TL;DR: I don't think the parent needs to returned, why are you calling a nonexistent function, and if you use clientCmdChatMessage, it will run your code anytime anyone says anything on the server besides if it's empty. If you want only yourself to be able to use the chatbot, and no one else on the server to be able to use it, use NMH_Type::Send(%this).


Are you actually calling a nonexistent function? I'm not sure, (this part has nothing to do with crashing, but rather, I'm fixing your code), but I don't think the parent needs to be returned. Maybe try calling the parent first and then do the rest of the stuff? Also, clientCmdChatMessage is what happens when anyone sends a chatmessage on the server you are on. So, anytime anyone says anything, if chatbotbios(%msg); isn't empty, it will make you say whatever chatbotbios(%msg); is. For example, Blockhead1235785 says "Hello", (let's suppose your code actually works), and then your code runs, and returns chatbotbios("hello"); as "asdf". The commandToServer() part makes you send a chatmessage, but since chatbotbios(%msg); returns something (I'm assuming), you will say "asdf" everytime someone says "hello". If you want it to only happen when you say "hello" and chatbot says "asdf", you should use NMH_Type::Send(%this); and work it out from there.
« Last Edit: July 06, 2014, 08:39:54 AM by Ninjaman 4 »

I was calling a non-existent function to try and determine where blockland was crashing. I found that blockland crashes in clientcmdchatmessage and doesn't even reach dochatbotstuff()

-2nd paragraph snip-
That is exactly what i'm doing.
« Last Edit: July 06, 2014, 02:35:29 PM by swatman64 »

I was calling a non-existent function to try and determine where blockland was crashing. I found that blockland crashes in clientcmdchatmessage and doesn't even reach dochatbotstuff()

You can just use echo..


Returning the parent never hurts. I do it in all packaged functions just out of habit so I have less chance of breaking anything.
Also, the last statement in a function is always returned, so even if he didn't put return in, it would still return the parent here.

The most likely cause of crashing is either the commandToServer('messageSent', chatbotBIOS(%msg));, another add-on, or the spaces in the non-existant functions (unlikely though, it should just put a syntax error up).

Try
calling the parent first and then do the rest of the stuff

function ChatBotBIOS(%in)
{
   %incheck = strLwr(%in);
   if(!isFile("config/client/chatbot/input.dat"))
   {
   warn("No chatbot input file found! Aborting...");
   return;
   }
   if(!isFile("config/client/chatbot/output.dat"))
   {
   warn("No chatbot output file found in 'config/client/chatbot'! Aborting...");
   return;
   }
   %input = new FileObject();
   %output = new FileObject();
   %input.openForread("config/client/chatbot/input.dat");
   %output.openForRead("config/client/chatbot/output.dat");
   while(!%output.isEOF && !%input.isEOF)
   {
      %inLine = %input.readLine();
      %outLine = %output.readLine();
      if(%incheck $= strLwr(%inLine))
      {
         return %outLine;
      }
   }
   %input.close();
   %output.close();
   %input.delete();
   %input.delete();
}


.isEOF() is a function, not a variable. That while loop will never exit.

You're also deleting %input twice, but that's just a bad thing to do, not something which would actually cause Blockland to crash or hang.

Ah, Mindless Ctrl+C and Ctrl+V is mindless. Thanks.