How to Create a Twitch Command Script for Streamlabs Chatbot — Part 4: Debugging

Nintendo Engineer
Jan 7 · 4 min read
Photo by Pascal van de Vendel on Unsplash

In Part 3 we finished the logic in our Mulder command and it worked beautifully. However, when it comes to programming, there seems to be this unwritten rule: Programs never work first try. It’s always an iterative process, whether it’s changes in how you expect something to work or weird bugs in your code. In this part we’ll focus on the latter. Knowing some debugging skills will really help when making your own commands, or just when programming in general. Let’s get to it!

Debugging

Logging is basically all I need to show you. Logging what your script is doing and when it’s doing it is the fastest way to find out where a bug could be hiding. Luckily, SC has a log method of its own: Parent.Log(string command, string message) and we are going to use that.

First off, that log method looks kind of bulky and, as we’re going to use it more than once, let’s create a utility method to wrap it in. The added benefit is that we don’t need to specify the command every time we want to log something. It stays the same anyway and doing it this way keeps us DRY:

You can place it all the way at the bottom, underneath the send_message method.

I noticed that we’re using the literal command name in two different places and this violates the DRY principle, so let’s fix that. Add a global variable to the ones we already have and replace all instances of “!mulder” with that variable:

Now, let’s add some log statements to the methods we’re using:

Good things are happening here. Reload the script in SC and then move to the log window by clicking the middle icon in the upper right:

The circular “info” button.

Clear the window with the reload symbol in the upper right and move to the Console section of SC. Enter !mulder again and move back to the log window. It should show you the logs as it flows through the different methods:

Looks good to me!

There are quite a few things that could go wrong in a program and having logs to pinpoint the location will save a lot of time when debugging these problems. If something were to go wrong in send_message, you would notice that by the missing logs. It makes it easy to find a bug, fix it, and continue. Imagine not having any clue why something is failing, you would be randomly guessing problems and get frustrated. Trust me, I’ve been there.

As you continue to create more advanced commands, you’ll recognize where and how to place logs to verify correct values are being passed around or to check if the method you need is actually being called. You can do a lot with logs.

Next step

In this part we learned about logging as a tool for debugging your script. This was an optional part, but in my opinion a very useful one. In the next and final Part 5 we will take a look at how to add a cooldown and a UI to Streamlabs Chatbot for your script. It’s optional, but nice to have, so if that sounds interesting, join me towards Part 5!

The Startup

Get smarter at building your thing. Join The Startup’s +800K followers.

Nintendo Engineer

Written by

Geotechnical Engineer by education, .NET Developer by trade, Nintendo fan by design. Find me on Discord: NintendoEngineer#3083

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +800K followers.

Nintendo Engineer

Written by

Geotechnical Engineer by education, .NET Developer by trade, Nintendo fan by design. Find me on Discord: NintendoEngineer#3083

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +800K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store