$(count)+switch/if Pepega Nightbot (twitch)

Hey Guys, I wanted to make a command, that counts the missed cannons in League of Legends, I mean, it’s a single command, with a counter, so a person writes !cannon, and it writes that xy missed $(count) cannon minions, and then, my idea was to, add a feature to this command which is it only counts if the game is League of Legends, so I coded it etc.

case ($(twitch $(channel) game) !== League of Legends):
$(channel) is not playing League of Legends, please don't use this command meaninglessly.;
$(channel) already missed $(count) cannon minions smileW;

Yea, it seems to be working, but its not, the problem is, when the streamer plays, sg. else, the nightbot message is the line what it should be, but it adds 1 more to the counter, so basicly it counts with every command use.
The reason why the code is a bit complicated, is that, first I tried to use if statements, it just did the same, so I decided to change the whole thing to switch, and when the expression was “$(twitch $(channel) game)”, not “true”, it just did the same thing, so this was my last try I’m out of ideas.
I also tried to use the counter mentioned here: https://community.nightdev.com/t/adding-a-command-that-adds-the-amount-specified-to-a-counter/22913 (with a few modifications ofc)
but it just did the same thing.
My final thought was to use sg. like mentioned here (but ofc with a little modification like -c=c-1): https://community.nightdev.com/t/is-there-a-count-reset/8985

But I dont actually no how to define this inside $(eval) nor that it would work or it would just lower the $(count)'s value with every use, like the $(count) works…

So guys my question is that, can somebody give me a freakin’ awesome solution for my porblem?
Thank you!

So I did a little research, and I found out that, nightbot executes every Variables, but it just wont show if it’s on another if/switch statement. I think it is kind of bs and it shouldn’t be this way, let’s hope the developers will find a way to fix this “bug”.

For the solution, I made a little custom API, which saves the number of executes into a txt file here is the code:

$strQuery = trim(urldecode($_GET['query']));
if ($strQuery == 'League of Legends')
$filename = "./path/counter.txt";
$file = fopen($filename, "r");
$pastAmount = fread($file, filesize($filename));
$newAmount = $pastAmount + 1;
echo "YOUR_CHANNEL already missed cannon minion ".$pastAmount."  times. smileW";
$file = fopen($filename, "w+");
fwrite($file, $newAmount);
echo 'YOUR_CHANNEL is not playing League of Legends, please stop spamming this command meaninglessly.';

in the txt file, you just put a number in the first line, and it will add +1 to it when the command is used, also pay attention for read and write permissions for this file.

and for the last the code of the command:
!addcom !cannon $(urlfetch http://somewebsite.whereyouwill.putthephp/cannon.php?query=$(twitch $(channel) game))

Ofc you have to put it on a website, and change the address like that.
Yes too much effort for a little thing, but I think it’s the only way to do this due to nightbot’s structure.
I hope I will help somebody who has the same issue.


It’s not really a bug since variables need to compiled before running an eval function. In your case a Custom API is indeed required :+1:

Knowing this, it’s not a bug, but I would say it’s illogical for a person who just got into nightbot coding. I didn’t want to downgrade your work, just wanted to share my experience, and my solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.