mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2018
Posts: 2
X
Bowl of petunias
OP Offline
Bowl of petunias
X
Joined: Apr 2018
Posts: 2
Thank you for any and all support that I may be given here. I will and do appreciate it!

I have a simple command below:
Code:
// Bingo Card Number Guess SYNTAX: !guess
on *:TEXT:!guess *:#mychannel:{
  msg $chan $nick Chose the Number $2- .
  write C:\PATH_TO_MIRC\text\bingoguess.txt < $+ $nick $+ > --- $2- ---
}


This cod will let the user type in '!guess #' where # is any number or unfortunately, any text...and write it to a file that gets uploaded with a separate program to my website I have for Bingo guesses. (That is a long story and isn't applicable.)

My question is this...how can I restrict any random text from being entered and only allow numbers in a certain range to be used, say 0 to 25? I have looked at regex and I don't know if that is the one thing I need to use or something else.

Can anybody give me advice on this?
Thank you for your time!

Last edited by XaviorPenguin; 30/04/18 12:45 AM. Reason: Question answered, thank you!
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
You'll probably also want to avoid guesses like 3.141592653589793

if ($2 !isnum 0-25) return
var %guess $int($2)
write filename $int($2)

You can't just automatically take the $int() of $2 because if you're allowing zero as a guess, that's what you get from taking the int of a text word.

Joined: Apr 2018
Posts: 2
X
Bowl of petunias
OP Offline
Bowl of petunias
X
Joined: Apr 2018
Posts: 2
Thank you very much! Adding that and changing one small variable, I am on the right path. Thank you!!

For those that want to know, here is the final code that is working for me:
Code:
// Bingo Card Number Guess SYNTAX: !guess
on *:TEXT:!guess *:#mychannel:{
  if ($2 !isnum 0-25) return
  var %guess $int($2)
  msg $chan $nick Chose the Number $2 .
  write C:\PATH_TO_MIRC\text\bingoguess.txt < $+ $nick $+ > --- $int($2) ---
}

Joined: Oct 2015
Posts: 112
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
I see this is marked as SOLVED already but I couldn't help but stumble here. I am unsure of how the number guessing works, but I noticed that you don't have any "check" to see if the user already made a guess or not. Assuming that they are only allowed ONE guess, I wrote the following code that should also work:

Code:
// Bingo Card Number Guess SYNTAX: !guess
on $*:TEXT:/^!guess\s\d+$/iS:#mychannel:{
  if (($2 isnum 0-25) && (!$read(bingoguess.txt, nts, < $+ $nick $+ >))) {
    write bingoguess.txt < $+ $nick $+ > --- $2 ---
    msg $chan $nick Chose the Number $2 $+ .
  }
}


If they are allowed MORE than one guess, then the following will work:
Code:
// Bingo Card Number Guess SYNTAX: !guess
on $*:TEXT:/^!guess\s\d+$/iS:#mychannel:{
  if ($2 isnum 0-25) {
    write bingoguess.txt < $+ $nick $+ > --- $2 ---
    msg $chan $nick Chose the Number $2 $+ .
  }
}


The first line with TEXT is regex which says that they need to type "!guess" with any number after it. It won't work with negatives or decimal places. The if statement (on the first code block) says that that number has to be between 0 and 25 AND that persons name can NOT already be in the text file. That way they can't make multiple votes. The second code block allows them to make multiple votes if that's what is intended. This is just another way to do it, hope it helps.


Link Copied to Clipboard