Jessecar96 / SteamBot

Automated bot software for interacting with Steam Trade
http://scrap.tf
MIT License
1.33k stars 910 forks source link

Starting bots by messaging #408

Closed ghost closed 11 years ago

ghost commented 11 years ago

Okay so I wanted to start bots by messaging them ".start (#)" or ".stop (#)" because sometimes one crashes and I want to not have to leave my computer to go to the server. Anyway here is my code:

    private readonly BotManager Bmanager;
    private int SIndex = -1;

            else if (message.StartsWith(".start")) //This is in the message area
            {
                if (message.Length >= 7)
                {
                    SIndex = -1;
                    int.TryParse(message.Substring(7), out SIndex);
                    Bmanager.StartBot (SIndex);
                    Bot.log.Success("Started bot: " + SIndex);
                }
            }
            else if (message.StartsWith(".stop"))
            {
                if (message.Length >= 6)
                {
                    SIndex = -1;
                    int.TryParse(message.Substring(6), out SIndex);
                    Bmanager.StopBot (SIndex);
                    Bot.log.Success("Stopped bot: " + SIndex);
                }
            }

When I try to do this I get this error:

[Keymac [BOT] 2013-07-30 08:41:25] ERROR: Unhandled exceptions in bot Keymac [BOT] callback thread: System.NullReferenceException: Object reference not set to an instance of an object at SteamBot.KeyUserHandler.OnMessage (System.String message, EChatEntryType type) [0x00c3a] in /home/twg/Desktop/SteamBot/SteamBot/KeyUserHandler.cs:270 at SteamBot.Bot.m__5 (SteamKit2.FriendMsgCallback callback) [0x0004b] in /home/twg/Desktop/SteamBot/SteamBot/Bot.cs:415 at SteamKit2.CallbackMsg.Handle[FriendMsgCallback](System.Action`1 handler) [0x00028] in /home/twg/Desktop/SteamBot/Lib/SteamKit2/SteamKit2/Steam3/SteamClient/CallbackMgr/CallbackMsg.cs:55 at SteamBot.Bot.HandleSteamMessage (SteamKit2.CallbackMsg msg) [0x00076] in /home/twg/Desktop/SteamBot/SteamBot/Bot.cs:404 at SteamBot.Bot.BackgroundWorkerOnDoWork (System.Object sender, System.ComponentModel.DoWorkEventArgs doWorkEventArgs) [0x00012] in /home/twg/Desktop/SteamBot/SteamBot/Bot.cs:678 at System.ComponentModel.BackgroundWorker.OnDoWork (System.ComponentModel.DoWorkEventArgs e) [0x00000] in :0 at System.ComponentModel.BackgroundWorker.ProcessWorker (System.Object argument, System.ComponentModel.AsyncOperation async, System.Threading.SendOrPostCallback callback) [0x00000] in :0

Although I think that this is the important part: System.NullReferenceException: Object reference not set to an instance of an object

waylaidwanderer commented 11 years ago

You can't message an offline bot and pass commands to the Bot Manager.

ghost commented 11 years ago

No I have 2 bots and message the online one.

waylaidwanderer commented 11 years ago

I'm guessing your Bmanager variable isn't actually assigned to.

Oh, and #307 - this isn't the place for programming help, but actual issues with SteamBot.

ghost commented 11 years ago
private readonly BotManager Bmanager;
private int SIndex = -1;