mIRC Homepage
Posted By: Cyrex Command with switches - 21/04/04 04:20 AM
I would like to know how I would go about creating a command that will see if multiple switches are used in the command, and then perform the command with the switches supplied.

Here's a small command with simple switch use I wrote:

alias test {
if ($1 == -r) {
exit
run $mircexe
}
if ($1 == -d) {
if ($isfile($mircdirtemp.log)) { .remove $shortfn($mircdirtemp.log) }
}
}

Let's say the user used the above command with a combination of switches:

/test -dr


The"test" command, with the switches, would delete the temp.log file, then restart mIRC.

But how can I fix my code so my command will see if more than one switch has been specified, and perform those actions? I don't want to use tons of if statements. I want the code small and clean.


How would I fix this code to see if the the user specified more than one switch, and perform the command using *all* the switches specified? I don't want to use tons of "if" statements.
Posted By: LocutusofBorg Re: Command with switches - 21/04/04 05:21 AM
Code:
[color:green]; detect if $2 is the switches[/color]
if ($left($2,1) == 1) {
  [color:green]; detect switch and act on it[/color]
  if (d isin $2) { do stuff }
  if (r isin $2) { do stuff }
}


Pretty sure your code for the -d switch is not gonna work tho - as soon as you type exit, mIRC closes - then there's no program running to restart the exefile. mIRC cannot restart itself far as I know.
Posted By: Cyrex Re: Command with switches - 21/04/04 06:08 AM
That code doesn't seem to be working...
Posted By: Cyrex Re: Command with switches - 21/04/04 06:20 AM
OK, I modified your code a little, and got it working!

Code:
alias test {
  if ($left($1,1) == -) {
    if (d isin $1) {
      if ($isfile($mircdirtemp.log)) { 
        .remove $shortfn($mircdirtemp.log)
      } 
    }
    if (r isin $1) {
      exit
      run $mircexe
    }
  }
}  
Posted By: Iori Re: Command with switches - 21/04/04 07:52 AM
Code:
alias test {
  if -*d* iswm $1 { .remove temp.log }
  if -*r* iswm $1 { run $mircexe | exit }
}
Posted By: MeStinkBAD Re: Command with switches - 23/04/04 09:24 AM
Here... I wrote this eons ago for dealing with switches...

Code:
ALIAS PARSEFLAGS {
  var %switch,%chars,%count,%list,%length,%char

  if ($left($1,1) !isin +-) { return }
  %switch = $left($1,1)

  if ($2 != $null) { %chars = $2 }
  else { %chars = abcdefghijklmnopqrstuvwxyz }

  %length = $len($1)
  %count = 0

  while (%count < %length) {
    inc %count
    %char = $mid($1,%count,1)
    if (%char isin +-) { var %switch = %char }
    elseif (%char isletter %chars) { %list = %list %switch $+ %char }
    elseif ((%char isnum) && (%list != $null)) { %list = %list $+ %char }
  }
  return %list
}


It parses -act5s to -a -c -t5 -s. You should be able to figure out what to do from there.
© mIRC Discussion Forums