mIRC Home    About    Download    Register    News    Help

Print Thread
#80052 21/04/04 04:20 AM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
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.

#80053 21/04/04 05:21 AM
Joined: Mar 2003
Posts: 1,271
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
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.


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
#80054 21/04/04 06:08 AM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
That code doesn't seem to be working...

#80055 21/04/04 06:20 AM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
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
    }
  }
}  

#80056 21/04/04 07:52 AM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Code:
alias test {
  if -*d* iswm $1 { .remove temp.log }
  if -*r* iswm $1 { run $mircexe | exit }
}

#80057 23/04/04 09:24 AM
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
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.


Beware of MeStinkBAD! He knows more than he actually does!

Link Copied to Clipboard