 Hey friends, it's Flare. I received a comment on a recent video about how to make a counter for your stream that doesn't reset when the bot is closed. I always like to say I'll help you solve the issues you have when you ask questions in my comments, so I'm putting my money where my mouth is and making a video in response to this question. So here is how to create a counter for your stream using persistent variables in Streamerbot. The key to having a counter not expire or reset when the bot is closed is to use persistent global variables. The data for these variables is saved in a dat file behind the scenes instead of just being saved in memory. So when the bot is closed and reopened, it's able to recover the previous value of these variables. In this example, I'll show you how to set up a command to leverage one of these variables. The most basic example of this is to just have one single command that both increments the variable and displays the updated count. To set this up, go to the actions tab, right click and select add. Name it whatever you want. In this case, we're calling it counter. Under subactions, the first thing we want to do is get the existing value of this variable if it already exists. Right click and choose add subaction, logic, global, get. In the dialog that appears, make sure global is selected in the dropdown and make sure the persistent checkbox is checked. This is what makes it the variable keep its value even after Streamerbot is closed. The variable name box is the name of the global persisted variable that you want to access. The destination variable is the temporary variable you want to store the value of the global in so you can use it in subsequent actions and subactions. The reason it's done this way is so you don't have to worry about the global variable getting updated behind the scenes by another action running concurrently. I'll just use persistent counter as the variable name and global persistent counter as the destination and we'll set a default to zero. This default value allows us to set what value this variable will start at if it hasn't been run yet and we don't have a stored value. Next, we want to increment this value by one. Right click and choose add subaction, logic, global, set. Use the same variable name again here, persistent counter. Then in the dropdown, choose increment and in the box next to it, enter one. You can use this to increment by any number you want, including negative numbers, in case you want to make a command to decrement this variable instead of increment. We'll talk about that later though. Next, and this is the part that seems a little bit unnecessary, but really isn't. We want to get the global variable again to update our local value before outputting the message. Let's just duplicate that first subaction we made to keep it easy. Technically, we don't need to set the default to zero this time we get it since we know that there's a value already set since we've just set it. So I'm going to go in and remove that now. Now we're ready to output the value of our counter. To do this, right click and choose add subaction, twitch, send message to channel. Set the message to use the destination variable from that global get subaction. In this case, I set the whole message to be value of this counter is global persistent counter. Now let's set up the command. Go to the commands tab, right click and choose add. In the commands box, put the name of the command you wish. In this case, I'll do exclamation counter. Now click the box next to action and choose the counter action we just made. We'll leave everything else alone for now and click okay, and we're ready to test. Now over in chat we can type exclamation counter to test our command. The first time it runs I expect to see it at one and then subsequent times I expect it to increment by one each time. Now to test the persistence of the counter, I'll close Streamerbot entirely. While we're closed, I can show you where the values of these persistent variables are kept. If you open your streamerbot folder and then the data sub folder, you should see a file named globals.dat. You open up this file with your text editor of choice, which is sublime, right? You'll see a big blob of text, which is actually just a JSON object containing all the global variables. Amongst all of this we can search for our variable persistent counter and we'll see the most recent value right here. This can be useful in case you need to manually edit one of these global variables, but I don't really recommend manually messing with this file unless you absolutely have to. Let's launch Streamerbot again and test this command. Now that it's loaded again, I'd expect to see the next number in the series when I type exclamation counter again, even though the bot was closed. Yep, there it is. The most common use I've seen for this kind of thing is a death counter, but it could also be fun to give your moderators of man to track all kinds of things. Sneezes on stream, times the streamer swears, times the streamer has gotten up and gone to the bathroom, really anything you can think of. You may also want to separate this out into a few different commands. For example, my death counter has a command just to show the count that anyone can use and then there's commands to increment and decrement by one and by five. There's also a command to set it to zero or set it to a specific number, but we're just talking about how to use these persistent variables to set up commands in the first place. So I'm not going to get into all of that. If this video has been helpful to you at all, please hit the like button, consider subscribing to the channel and leave a comment below about what you'd like to see next. I've got more videos coming soon, but I wanted to squeeze this in to prove to you all that I'm listening to your requests, and I really will do my best to help if you just ask for help. I stream on Sunday and Monday nights over at twitch.tv slash flair, and I'm always down to talk about bot stuff on stream. I'm usually willing to drop whatever I'm doing and show you stuff in my own bot during stream too. I also have a small but growing discord server where I'm available off stream to talk about this kind of stuff and answer your questions. Thanks again for watching, and as always, remember to spread love, not hate.