mIRC Home    About    Download    Register    News    Help

Print Thread
A script crashing my IRC #223564 28/07/10 07:50 PM
Joined: Jul 2010
Posts: 1
M
Makoko Offline OP
Mostly harmless
OP Offline
Mostly harmless
M
Joined: Jul 2010
Posts: 1
Basically it's a simple die roller, only recognizing a d6. But it locks up and freezes my IRC window whenever it runs. I already know that there's some problem in it somewhere preventing it from running properly (it doesn't repeat properly in the while loop), but that still shouldn't be enough to crash my IRC.

Code:
on *:TEXT:!r*:#:{
  if $me == %bot {
    if ($$2 isnum) {
      if $$3 == d6 {
        set %i 1
        while %i <= $$2 {
          timer 1 2 set %outcome $rand(1,6)
          timer 1 3 msg #$chan %outcome
          timer 1 4 inc %i 1
        }
      }
    }
  }
}


I think it has to do with the loop running infinitely, I don't know. Maybe I'm just not seeing the obvious. Any ideas?

Last edited by Khaled; 28/07/10 08:25 PM.
Re: A script crashing my IRC [Re: Makoko] #223566 28/07/10 08:21 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Yes, your timers are the whole problem.
Code:
on *:TEXT:!r*:#:{
  if ($me == %bot) && ($2 isnum) && ($3 == d6) {
    var %i = 1
    while (%i <= $2) {
      var %outcome = %outcome $rand(1,6)
      inc %i
    }
    msg $chan %outcome
  }
}

You don't need your $$ in this case since you explicitly state they need to be a certain value.

By the way, as described in the help file, you can always break out of infinite loops by pressing Ctrl+Break/Pause

Last edited by 5618; 28/07/10 08:29 PM.
Re: A script crashing my IRC [Re: Makoko] #223568 28/07/10 10:30 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Here's a basic die roller that accepts any sided dice and any number of dice:

Code:
on *:text:!roll *:#: {
  ; $2 should be the format of 2d6.  If you want another format, this can easily be adjusted.
  var %numdice = $gettok($2-,1,100), %dicesides = $gettok($2-,2,100)
  if (%numdice !isnum || %dicesides !isnum) { msg $chan ERROR: Wrong format.  Example:  !roll 3d6 }
  while (%numdice) {
    var %rolls = %rolls $rand(1,%dicesides)
    dec %numdice
  }
  msg $chan %rolls
}


Example Uses:
!roll 3d6
!roll 2d12
!roll 4 d 5

Last edited by Riamus2; 28/07/10 11:41 PM.

Invision Support
#Invision on irc.irchighway.net
Re: A script crashing my IRC [Re: Riamus2] #223569 28/07/10 10:43 PM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
little note, you need to use $2- instead of $2 in your $gettok if you want the '!roll 4 d 5' case to work


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: A script crashing my IRC [Re: Wims] #223570 28/07/10 11:42 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Oops. That's what I get for showing another way that would work and not testing it first. Fixed. laugh


Invision Support
#Invision on irc.irchighway.net
Re: A script crashing my IRC [Re: Riamus2] #223576 29/07/10 10:59 AM
Joined: Feb 2009
Posts: 133
C
chacha Offline
Vogon poet
Offline
Vogon poet
C
Joined: Feb 2009
Posts: 133
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
  }
}


WorldDMT
Re: A script crashing my IRC [Re: chacha] #223579 29/07/10 11:54 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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
Re: A script crashing my IRC [Re: chacha] #223580 29/07/10 12:42 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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


Yeah, I considered putting support in for capital D, but that's not really considered a valid format for D&D's dice, which is really what you're talking about when using 2d4 for similar format. I could add in a variety of other checks, such as making it only work if the d4 is a valid dice size. I just did a very basic one to show how it can be done. We could also strip out control codes to avoid those possible problems and a variety of other tweaks depending on how it's being used. I just left it as a basic script as mentioned in the post. It's just a template of how you can do dice before adding in any extras. I probably should have noted all of the potential "options" you can add to it to make it work better depending on the user's situation.

Here are some things that can be added if needed by the user:

*Support for capital D in 2d4
*Different error messages depending on input
*Limit the sides of dice to valid numbers (valid being whatever the rules say for the game the dice are being used in)
*Different output format to allow for a better display
*Set it up in an alias so it can return the dice in a way that can easily be used either with echo/msg/notice/etc or used in a script that makes use of the dice values
*Sort the rolls in a way that makes it easier to look at (for example, Yahtzee would benefit from sorting because you're looking for "pairs" and "runs")

And, yes, I forgot to put in halt/return/else in the check.


Invision Support
#Invision on irc.irchighway.net
Re: A script crashing my IRC [Re: jaytea] #223582 29/07/10 02:34 PM
Joined: Feb 2009
Posts: 133
C
chacha Offline
Vogon poet
Offline
Vogon poet
C
Joined: Feb 2009
Posts: 133
ty for the info smile


WorldDMT
Re: A script crashing my IRC [Re: Makoko] #223583 29/07/10 02:56 PM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
Why use a while loop, when $str() can be used?

Code:
on *:text:!roll *:#: {
  tokenize 32 $lower($2-)
  if (!$regex($1-,^(\d+)\x20?d\x20?(\d+)$)) { 
    msg $chan ERROR: Wrong format.  Example:  !roll 3d6 
  }
  else { 
    msg $chan $calc($($str($!r(1,$regml(2)) + $chr(32),$regml(1)),2)) 
  }
}



...maybe I am just showing off :\
though this would limit the amount of rolls able to be preformed b/c of mIRC's line-to-long thing

Last edited by FroggieDaFrog; 29/07/10 02:57 PM.

I am SReject
My Stuff