mIRC Homepage
Posted By: Daedalus while loop - 27/08/04 03:36 PM
I'm trying to make an alias for /join.
I want to type /j #channel1 #channel2 channel3 etc
and it will join all the channels I specify.

Code:
  
j {
var %channels = $0
while (%channels >= 0) {
join %channels
dec %channels
}
}


Any ideas on how to make it work?
Posted By: Coolkill Re: while loop - 27/08/04 04:30 PM
Either of the following will work and which one you use depends on your personal choice.

This will make it join the first channel, first, and the last, last.

alias j {
var %i = 1
while ($numtok($1-,32) >= %i) {
join $gettok($1-,%i,32)
inc %i
}
}

This will make it join the last channel, first, and the first channel, last.

alias j {
var %i = $numtok($1-,32)
while (%i) {
join $gettok($1-,%i,32)
dec %i
}
}

Hope this helps.

Eamonn.
Posted By: Kelder Re: while loop - 27/08/04 04:32 PM
/join #channel1,#channel2,#channel3

no need for a while loop...

but since you want an alias
j { var %i = 1 | while ($gettok($1-,%i,32)) { join $v1 | inc %i } }
Posted By: kocam Re: while loop - 27/08/04 05:25 PM
alias j join $*
Posted By: Daedalus Re: while loop - 27/08/04 05:40 PM
One more thing...I want it to automaticlly put # in front of the channel names...
Posted By: Coolkill Re: while loop - 27/08/04 06:10 PM

join $gettok($1-,%i,32)

becomes,

join $+(#,$gettok($1-,%i,32))


Eamonn.
Posted By: starbucks_mafia Re: while loop - 27/08/04 07:33 PM
Try this (put it in the Remotes section):
Code:
on *:start:unset %maxtargets.*
raw 005:* MAXTARGETS=*:set %maxtargets. $+ $cid $int($gettok($matchtok($1-,MAXTARGETS=*,1,32),2,61))
alias j {
  var %i = 1, %maxt = $iif($eval($+(%,maxtargets.,$cid),2),$v1,1), %j, %chans
  while %i <= $0 {
    %j = 1
    %chans = $null
    while (%j <= %maxt) && (%i <= $0) {
      %chans = $addtok(%chans, $eval($+(#$$,%i),2), 44)
      inc %i
      inc %j
    }
    join %chans
  }
}


It's untested but I think it should work.
Posted By: Sigh Re: while loop - 28/08/04 06:53 AM
$matchtok doesn't support wildcards so just leave off the * or use $wildtok, same thing
Posted By: starbucks_mafia Re: while loop - 28/08/04 12:13 PM
Ahh yes, in that case it should use $wildtok, just in case there's a token like MADMAXTARGETS=MelGibson that could throw off $matchtok.
© mIRC Discussion Forums