mIRC Homepage
Posted By: Lhurgoyf3 Testing while loops - 25/09/06 07:18 PM
I made a little script to duplicate channels and amaze your friends so I could test while loops

Code:
alias chanduper {
  ;;variables  
  var %cd.chan = $?="What channel do you want to copy?"  
  var %cd.numchan = $?="How many copies?"
  var %cd.op = $?!="Deop in all of the channels?"
  ;;while loop  
  while (%cd.numchan) {
    var %cd.chan = $instok(%cd.chan,,2,46)
    var %cd.chan = $remove(%cd.chan,.)
    var %cd.join = $addtok(%cd.join,%cd.chan,44)
    if (%cd.op) { mode %cd.chan -o $me }
    dec %cd.numchan
  } 
  join %cd.join
}


It works, but I get error messages equal to the number of copies I wanted to make. The error says:
$chan No such channel
(the channels are still joined though...)

comments?
Posted By: Lpfix5 Re: Testing while loops - 25/09/06 07:30 PM
Quote:
I made a little script to duplicate channels and amaze your friends so I could test while loops

Code:
alias chanduper {
  ;;variables  
[color:red]var %x = 1[/color] , %cd.chan = $?="What channel do you want to copy?"  , %cd.numchan = $?="How many copies?" , %cd.op = $?!="Deop in all of the channels?"
  ;;while loop  
  while ([color:red]%x <=[/color] %cd.numchan) {
[color:red]join $+($chr(35),%cd.chan,%x)
if ($me isop $chan) && (%cd.op) { mode $+($chr(35),%cd.chan,%x) -o $me }
inc %x[/color]
   } 
}


It works, but I get error messages equal to the number of copies I wanted to make. The error says:
$chan No such channel
(the channels are still joined though...)

comments?


Notice how you need a while loop to have from to from what i mean is have a small number like 1 go to x amount like 20 then have the script increment the %x till it reaches 20 it will loop till then and stop else your not assinging a loop and I wasnt sure what you wanted done but was just to show u
Posted By: Lhurgoyf3 Re: Testing while loops - 25/09/06 07:34 PM
It is the same thing
while (x) means that while x != 0, do stuff
so if I set x to 10 and dec it once every time, it will loop 10 times.
Posted By: Lpfix5 Re: Testing while loops - 25/09/06 07:39 PM
yeah your right

my bad
Posted By: Scorpwanna Re: Testing while loops - 25/09/06 07:40 PM
The dec method works too, and saves lines of code.
Posted By: Scorpwanna Re: Testing while loops - 25/09/06 07:42 PM
I vote it's an mIRC bug, who's with me?
Posted By: Lhurgoyf3 Re: Testing while loops - 25/09/06 07:45 PM
It shouldnt be a bug, although it is possible. I wrote it another way and it didnt do that (echo #chan doesnt exist)
Posted By: Lpfix5 Re: Testing while loops - 25/09/06 09:53 PM
Well It could be the server your on that only allows you X amount of channels to be on their network.

For example I believe Unreal IRCD = 8 channels maximum unless forced by an IRCOP
Posted By: Lhurgoyf3 Re: Testing while loops - 26/09/06 12:56 AM
Ok this is the final code. Everything works and there are no errors (assuming the user does not try to mess up on purpose). I didnt do error checking because it doesnt matter for this little experiment.

Code:
alias chanduper {
  var %cd.chan = $?="What channel do you want to copy?"  
  var %cd.num = $?="How many copies?"
  var %cd.num2 = %cd.num
  var %cd.op = $?!="Deop in all of the channels?"
  while (%cd.num) {
    var %cd.chan = $instok(%cd.chan,,2,46)
    var %cd.chan = $remove(%cd.chan,.)
    var %cd.join = $addtok(%cd.join,%cd.chan,44)
    dec %cd.num
  } 
  join %cd.join
  if (%cd.op) {
    inc %cd.num
    echo -ae %cd.join
    echo -ae %cd.num
    while (%cd.num <= %cd.num2) {
      mode $gettok(%cd.join,%cd.num,44) -o $me
      inc %cd.num
    }
  }
}
Posted By: jaytea Re: Testing while loops - 27/09/06 08:47 PM
your problem is quite simply that you're sending the mode command BEFORE you've sent the corresponding join command (dunno how this could possibly be construed as a mirc bug laugh!), i.e:

Code:
join #chan | mode #chan -o $me


is ok (providing #chan is empty, and unregistered, before you join it) but:

Code:
mode #chan -o $me | join #chan


is obviously invalid. what i recommend you do is build a list of mode commands, $+(mode #chan1 -o $me,$crlf,mode #chan2 -o $me,$crlf,...) where $crlf is used to send multiple commands to the server in the same packet

then you can send the join command at the end, and the mode if applicable
Posted By: Scorpwanna Re: Testing while loops - 27/09/06 10:58 PM
Or just use a timer.

join #chan | .timermodeme 1 1 mode #chan -o $me
© mIRC Discussion Forums