mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Hello.
I would like to know, how to set up, so if user writes a command, and the second variable is something else than -cm1 -cm2 or -cm3 it shows - Usage : !command -cm1 -cm2 or -cm3
If you didnt understand look at this.

Code:
on *:TEXT:!command*:*:{
  if ($2 == -cm1) { msg $nick Hello one | halt }
  if ($2 == -cm2) { msg $nick Hello two | halt }
  if ($2 == -cm3) { msg $nick Hello three | halt }

And so if user writes something like !command -cm4 or !command -whatever it shows - Usage : !command -cm1 -cm2 or -cm3

Last edited by spermis; 30/01/09 04:18 PM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Use $istok, and you should use return instead of halt here, i'm sure you don't need to stop the whole script.
Code:
on *:TEXT:!command*:*:{
if (!$istok(-cm1 -cmd2 -cm3,$2,32)) msg $nick Usage : !command -cm1, -cm2 or -cm3
else {
;your script here
 }
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Thanks! This worked.

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Hey cool! I just wanted you to know what I learned from testing. Using $chr(32) with tokens is slower than other characters.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Huh? If you don't mind freezing your sys for a minute (or 3)...
Code:
alias tokentest {
  var %char = 25, %endchar = 40, %iterations = 100000, %items = ••• ––– ˜˜˜ ™™™ œœœ

  ECHO -agtc info * Test of %iterations $!istok-iterations on chars $!chr( $+ %char $+ ) to $!chr( $+ %endchar $+ )
  ; loop chars
  while (%char <= %endchar) {
    ; build string of %items
    var %nr = 1, %string
    while $gettok(%items,%nr,32) {
      var %string = $addtok(%string,$v1,%char)
      inc %nr
    }
    ; bench: iterative istok on string of %items
    var %a = 1, %start = $ticks
    while (%a <= %iterations) {
      .ECHO -q $istok(%string,˜˜˜,%char)
      inc %a
    }
    ECHO -ag $!chr( $+ %char $+ ): $calc($ticks - %start) ticks
    inc %char
  }

  ECHO -agtc info * done.
}

...my bench:
[12:18:43] * Test of 100000 $istok-iterations on chars $chr(25) to $chr(40)
$chr(25): 4234 ticks
$chr(26): 4204 ticks
$chr(27): 4187 ticks
$chr(28): 4188 ticks
$chr(29): 4187 ticks
$chr(30): 4188 ticks
$chr(31): 4187 ticks
$chr(32): 4172 ticks
$chr(33): 4187 ticks
$chr(34): 4266 ticks
$chr(35): 4188 ticks
$chr(36): 4187 ticks
$chr(37): 4187 ticks
$chr(38): 4188 ticks
$chr(39): 4187 ticks
$chr(40): 4172 ticks
[12:19:50] * done.

confused

...nothing but the usual variation. Note that (at least on my sys, and for less iterations) the "first" char always takes a bit longer (whatever char processed) - due to the way my sys allocates ressources. That's why I placed chr(32) right in the middle.

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
It's possible, since mirc play itself with space, but as was demonstrated, the speeed isn't really different...


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Basically I teste different ways of comparing data and found that isin was the fastest. Then I took it a step further and checked to see which is the fastest to seperate tokens with ... Give me a few and I will show you the test.

Code:
alias SpeedTest {

  ;Test 1
  var %ticks = $ticks
  var %cnt 1
  ; while (%cnt <= %tr) {
  while (%cnt <= 20000) {
    var %ex = $iif(t isin r t s u,yes,no)
    inc %cnt
  }
  msg $active 32: $calc($ticks - %ticks)

  ;Test 2
  var %ticks = $ticks
  var %cnt 1
  while (%cnt <= 20000) {
    var %ex = $iif(t isin r.t.s.u,yes,no)


    inc %cnt
  }
  msg $active 46: $calc($ticks - %ticks)
}

1st try:
32: 1576
46: 1388

2nd try:
32: 1560
46: 1389

3rd:
32: 1575
46: 1404

Using underscore $chr(95) instead of period.
32: 1592
95: 1389

32: 1576
95: 1389

32: 1560
95: 1388

I havent found a faster character. All characters seem to be the same speed except for the space, $chr(32), which is slower to evaluate.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Ah, now I see your isse; the difference you describe is caused by the parser, not the processing routine itself.

To demonstrate this, I increased the length of the text-to-parse and the No. of repetitions, and added an initial "dummy loop" to take the "ressources allocation" into account:
Code:
alias SpeedTest2 {
  var %reps = 100000

  ; dummy run to prevent the allocation issue
  var %cnt = 1
  while (%cnt <= %reps) {
    var %ex = $iif($true,yes,no)
    inc %cnt
  }
  echo -a ----

  var %ticks = $ticks, %cnt = 1
  while (%cnt <= %reps) {
    var %ex = $iif(t isin r.t.s.u.ma.ne.pi.wo,yes,no)
    inc %cnt
  }
  echo -a 46 (text): $calc($ticks - %ticks)

  var %ticks = $ticks, %cnt = 1
  while (%cnt <= %reps) {
    var %ex = $iif(t isin r t s u ma ne pi wo,yes,no)
    inc %cnt
  }
  echo -a 32 (text): $calc($ticks - %ticks)

  var %ticks = $ticks, %cnt = 1, %string = r.t.s.u.ma.ne.pi.wo
  while (%cnt <= %reps) {
    var %ex = $iif(t isin %string,yes,no)
    inc %cnt
  }
  echo -a 46 (%var): $calc($ticks - %ticks)

  var %ticks = $ticks, %cnt = 1, %string = r t s u ma ne pi wo
  while (%cnt <= %reps) {
    var %ex = $iif(t isin %string,yes,no)
    inc %cnt
  }
  echo -a 32 (%var): $calc($ticks - %ticks)
}


----
46 (text): 5625
32 (text): 6922
46 (%var): 5640
32 (%var): 5610

isin or istok or whatever - to my limited knowledge mIRC parses the code mainly along commas, brackets and of course - spaces smile

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Thanks Horstl. Nice to know.

Last edited by DJ_Sol; 03/02/09 02:21 PM.

Link Copied to Clipboard