Originally Posted By: chacha
use $lower bcz of "D" mabe that won't work with chr 100
and u have to stop the code after the check of numbers by adding halt, return, or if/else, orelse the loop will continue the execution

Code:
on *:text:!roll *:#:{
  tokenize 100 $lower($2-)
  if ($1-2 !isnum) msg # ERROR: Wrong format.  Example: !roll 3d6
  else {
    var %n $1,%d $2
    while (%n) var %r %r $r(1,%d),%n %n - 1
    msg # %r
  }
}


if ($1-2 !isnum) is always satisfied if $2 exists. reason being, $1-2 will contain a space which automatically renders it non-numerical. you would have to expand that to if ($1 !isnum) || ($2 !isnum) to have it behave the way you expect, but you'll find that also lets through input such as !roll -1d1 (which causes an infinite loop), !roll 1d1.5 (which, though rounded by $r(), should probably be considered invalid) etc.

to check if $1 and $2 are both strings of digits (that is to say, $2 exists and $1 $+ $2 is a string of digits) you can use the following:

Code:
if ($+(+, $1, $$2.) isnum) {


in general, if ($+(+, N, .) isnum) is true if and only if N is composed entirely of (1 or more) digits


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde