mIRC Home    About    Download    Register    News    Help

Print Thread
if $2 is something else then #208880 30/01/09 04:18 PM
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.
Re: if $2 is something else then [Re: spermis] #208881 30/01/09 04:36 PM
Joined: Jul 2006
Posts: 3,807
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,807
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
 }
}


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: if $2 is something else then [Re: Wims] #208951 01/02/09 01:23 PM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Thanks! This worked.

Re: if $2 is something else then [Re: Wims] #209018 03/02/09 10:51 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
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.

Re: if $2 is something else then [Re: DJ_Sol] #209019 03/02/09 11:27 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
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.

Re: if $2 is something else then [Re: DJ_Sol] #209020 03/02/09 12:12 PM
Joined: Jul 2006
Posts: 3,807
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,807
It's possible, since mirc play itself with space, but as was demonstrated, the speeed isn't really different...


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: if $2 is something else then [Re: Horstl] #209021 03/02/09 12:47 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
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.

Re: if $2 is something else then [Re: DJ_Sol] #209028 03/02/09 01:35 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
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

Re: if $2 is something else then [Re: Horstl] #209036 03/02/09 02:16 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
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.