mIRC Home    About    Download    Register    News    Help

Print Thread
How to make a twitch bot recognize negative number #257055 10/03/16 11:47 PM
Joined: Mar 2016
Posts: 2
K
KaRappa Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
K
Joined: Mar 2016
Posts: 2
Hello, I want to make a simple code where the bot would recognize whether the number a person sending the command is typing would be positive or negative. It would look something like that:

Quote:
Person: !number 3
Bot: The number is positive.

or
Quote:
Person: !number -3
Bot: The number is negative.


I have tried putting a variable after the command like so:
Code:
on *:TEXT:!number %number:#:

But this doesn't seem to work.

Any idea how should it look like? Thank you in advance for helping me smile

Re: How to make a twitch bot recognize negative number [Re: KaRappa] #257056 11/03/16 12:52 AM
Joined: Nov 2009
Posts: 295
P
pball Offline
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
on *:text:!number *:#: if ($2 < 0) msg $chan The number is negative | elseif ($2 > 0) msg $chan The number is positive

that should work and also zero isn't positive or negative if you didn't know, so the script doesn't say anything for zero lol


http://scripting.pball.win
My personal site with some scripts I've released.
Re: How to make a twitch bot recognize negative number [Re: pball] #257058 11/03/16 12:21 PM
Joined: Mar 2016
Posts: 2
K
KaRappa Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
K
Joined: Mar 2016
Posts: 2
Yes, I know, the example I gave is for me to learn how those work for a bigger project smile

The bot seems to recognize the numbers in the command I gave in the example, but I also have another question.

Is there a way to make the bot recognize a number in a sentence? And if there is more than one number, is it possible for the bot to "care" only about the first one? Example:
Quote:
Person: The number 20 is bigger than 19.
Bot: Number 20 is positive.

Re: How to make a twitch bot recognize negative number [Re: KaRappa] #257065 12/03/16 01:32 AM
Joined: Nov 2009
Posts: 295
P
pball Offline
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
This one is a little more advance as it uses regex matching. It will find the first number that is by itself. So it will not find anon31 but it will find 975.

on $*:text:/^.*? (\d+) /:#: echo -a number $regml(1)

The $ in the on $*:text allows you to use regex in the on text event. The /^.*? (\d+) / is the regex string. If you want to know more just ask.


http://scripting.pball.win
My personal site with some scripts I've released.