I am making a C# program that talks to people using AIML, it is using networking so it can talk to multiple people at once.

Here is my get message handler:

private void MessageRecieved(UserMessage message)
        {
            if (message.getMessageType() == Enumerations.UserMessageType.incomming_text_message)
            {       
                
                    conversationHTML += online[message.getUsername()].FriendlyName + " says: "
                        + "<font color=\"Gray\">" + message.getUserPayload() + "</font><br />";
                                    
                    string recvMsg = message.getUserPayload();

                    string send = getReply(recvMsg);
                         
                    switchboard.sendMessage(new UserOutgoingMessage("Times New Roman", send));             
                   
                    conversationFrame.DocumentText = conversationHTML;

                //}));
            }
        }

My getReply function which calls the AIML:

private string getReply(string msg)
        {      
            try
            {
                return bot.getOutput(msg);
            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString() + Environment.NewLine + msg);
                return null;
            }
        }

Now here is my AIML class: I did not program it but I found it. It works well by itself, but for some reason its not working here and I can't pinpoint it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AIMLbot;

namespace Chatbot
{
    class alice
    {
        private Bot myBot;
        private User myUser;

        /// <summary>
        /// Create a new instance of the ALICE object
        /// </summary>
        public alice()
        {
            myBot = new Bot();
            myUser = new User("consoleUser", myBot);
        }

        /// <summary>
        /// This initialization can be put in the alice() method
        /// but I kept it seperate due to the nature of my program.
        /// This method loads all the AIML files located in the \AIML folder
        /// </summary>
        public void Initialize()
        {
            myBot.loadSettings();
            myBot.isAcceptingUserInput = false;
            myBot.loadAIMLFromFiles();
            myBot.isAcceptingUserInput = true;
        }

        /// <summary>
        /// This method takes an input string, then finds a response using the the AIMLbot library and returns it
        /// </summary>
        /// <param name="input">Input Text</param>
        /// <returns>Response</returns>
        public String getOutput(String input)
        {
            Request r = new Request(input, myUser, myBot);
            Result res = myBot.Chat(r);
            return (res.Output);
        }
    }
}

Here is the error I keep getting: (I typed it out and skipped unimportant things)

System.FormatException ...
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at
System.Number.Parse...
at 
System.Double.Parse...
at
System.Convert.ToDouble
at
AIMLbot.Bot.get_TimeOut()
at
AIMLbot.Utils.Node.Evaluate
at
AimlBot.Bot.Chat(request request)
at CHatbot.alice.getOutput(String input) in blabla/Chatbox.cs:line 44 at blabla.GetReply(String msg) in blabla line 102 

^ The above is my getReply function at this line: return bot.getOutput(msg);

Msg: hi

I can't seem to find out whats wrong. I was going to make a communication client between another program using pipes to send data, but that would be unnecessary imo

Edited 5 Years Ago by scriptkiddy: n/a

It looks like there is a problem with one of the internal values. I say this because of the AIMLbot.Bot.get_TimeOut() line. It looks like it's trying to parse some text into a double and it fails. Are you sure the line myBot.loadSettings(); is actually loading the settings?

It should be loading the settings, its not throwing any exceptions either and its also void

Edited 5 Years Ago by scriptkiddy: n/a

I'd post on whatever support forums there are for the code you downloaded, since it's an internal error.

I retested it on a blank file with only a few lines of code and it is working fine, but when I try to add it into my winsocket client I am getting this error after cleaning up my code:

System.Null.ReferenceException:
at AIMLbot.Bot.Chat(Request request)
at Client.ChatWindow.getReply(String msg) in blabla folder path line 109

Msg recv: hi

My new code removed the class and it now looks like this:

Globals:

private Bot myBot = new Bot();
private User myUser;

Form init:

myBot.loadSettings();           
myBot.isAcceptingUserInput = false;
myBot.loadAIMLFromFiles();
myBot.isAcceptingUserInput = true;

User connection:

myUser = new User(username, myBot);

Recv message from user:

Same code as before, calls get reply

New getReply:

private string getReply(string msg)
        {      
            try
            {
                Request r = new Request(msg, myUser, myBot);
                Result res = myBot.Chat(r);
                return res.Output;
            }
            catch(Exception e)
            {                
                MessageBox.Show(e.ToString() + Environment.NewLine + msg);
                return null;
            }
        }

Here is line 109: Result res = myBot.Chat(r);

It works fine with this code (not my code)

using System;
using AIMLbot;

namespace ConsoleBot
{
    class Program
    {
        static void Main(string[] args)
        {
            Bot myBot = new Bot();
            myBot.loadSettings();
            User myUser = new User("consoleUser", myBot);
            myBot.isAcceptingUserInput = false;
            myBot.loadAIMLFromFiles();
            myBot.isAcceptingUserInput = true;
            while (true)
            {
                Console.Write("You: ");
                string input = Console.ReadLine();
                if (input.ToLower() == "quit")
                {
                    break;
                }
                else
                {
                    Request r = new Request(input, myUser, myBot);
                    Result res = myBot.Chat(r);
                    Console.WriteLine("Bot: " + res.Output);
                }
            }
        }
    }
}

But its failing with mine for some reason

Edited 5 Years Ago by scriptkiddy: n/a

*FACEPALM* I solved the problem, for anyone who has this same problem here is what you do:

Create the bot and put its functions in the MAIN form, since the child form is created multiple times.

Pass the form handle to your child form and put all the functions in your MAIN form. Then call the getReply function thats in your MAIN form (should be Form1.getReply) (make sure its public) and it should work

This article has been dead for over six months. Start a new discussion instead.