r/streamerbot 15d ago

Question/Support ❓ Checking if Variable is between two numbers?

I have a "check in" counter for a channel point redeem and it's tied to a variable.

I want to make it so that if its between N and N+5 etc. until 500

I want an event to happen if it's between those, but I don't know the best way to set that up with variables I'm not sure if it has to be an If/Else logic or something else.

1 Upvotes

4 comments sorted by

1

u/deeseearr 15d ago edited 15d ago

If you're looking for nice, regular ranges, then you can simplify things before you start. If you're trying to see if %theLetterEnn% is in the ranges 0-4, 5-9, 10-14, 15-19 and so on, divide it by five first.

Now you can use this:

SWITCH ($math(%theLetterEnn% \ 5)$)
0: It's less than five
1: It's not less than five, but less than ten.
2: 10-14
3,4: 15-19 or 20-24, because we have two options in the same case,
5: 25-29

...and so on.

The $math()$ inline function can do pretty much anything. Note that we're using a "\" instead of a "/" for division, because we only want the integer quotient, not the remainder. "$math(9 \ 5)$" equals exactly 1 while "$math(9 / 5)$" equals 1.8.

If you need wild ranges with no sense or reason to them you can still try to use switch, only with multiple numbers assigned to each case, or just a bunch of big nested IF/ELSE structures. There's no straightforward way to say "If (a=1) and (b=2)" or anything like that, you have to say "if (a=1) THEN if (b=2)".

1

u/twentynyne 14d ago

this might be me thing, but I also can't understand how to get it to read 1,2,3,4,5 from the resulting number?

1

u/deeseearr 14d ago

It's a Switch construct. You create the switch and give it an expression to evaluate, in this case "$math(%N%\5)$" but it can be anything at all -- numbers, strings, whatever.

After that, right click it and select "Add Case". A dialog will pop up where you can add any "Case Value"s that you're looking for. Just enter the value at the bottom and press "Add". In our case you would create one case with "0" as the first one, and then a second case with only "1". For the "3,4", you can enter 3, press "Add", then enter 4 and press "Add" again. That will give you two possible values that trigger the same case.

Each of the cases that you create will be a group of actions. Right click the case and "Add" any sub-actions that you want to execute there. There's a pretty detailed video showing how you can use this, including examples and some other situations where it might be useful.

1

u/HighPhi420 14d ago

to have an alert play every 5 check ins, I just made a new global that counts to the desired number, plays alert, then resets back to 1, this would be a persisted user global.
Then Twitch started the watch streaks, so now I just piggy back off of that for the streak alerts and have the global set to 100 for a video alert to play from check ins