mIRC Home    About    Download    Register    News    Help

Topic Options
#160339 - 25/09/06 08:18 PM Testing while loops
Lhurgoyf3 Offline
Pikka bird

Registered: 25/09/06
Posts: 13
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?

Top
#160340 - 25/09/06 08:30 PM Re: Testing while loops
Lpfix5 Offline
Hoopy frood

Registered: 10/08/05
Posts: 1052
Loc: Canada
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

Top
#160341 - 25/09/06 08:34 PM Re: Testing while loops
Lhurgoyf3 Offline
Pikka bird

Registered: 25/09/06
Posts: 13
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.

Top
#160342 - 25/09/06 08:39 PM Re: Testing while loops
Lpfix5 Offline
Hoopy frood

Registered: 10/08/05
Posts: 1052
Loc: Canada
yeah your right

my bad
_________________________
Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }

Top
#160343 - 25/09/06 08:40 PM Re: Testing while loops
Scorpwanna Offline
Fjord artisan

Registered: 20/09/03
Posts: 261
Loc: Arkansas, US
The dec method works too, and saves lines of code.
_________________________
We don't just write the scripts, we put them to the test! (ScriptBusters)

Top
#160344 - 25/09/06 08:42 PM Re: Testing while loops
Scorpwanna Offline
Fjord artisan

Registered: 20/09/03
Posts: 261
Loc: Arkansas, US
I vote it's an mIRC bug, who's with me?
_________________________
We don't just write the scripts, we put them to the test! (ScriptBusters)

Top
#160345 - 25/09/06 08:45 PM Re: Testing while loops
Lhurgoyf3 Offline
Pikka bird

Registered: 25/09/06
Posts: 13
It shouldnt be a bug, although it is possible. I wrote it another way and it didnt do that (echo #chan doesnt exist)

Top
#160346 - 25/09/06 10:53 PM Re: Testing while loops
Lpfix5 Offline
Hoopy frood

Registered: 10/08/05
Posts: 1052
Loc: Canada
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
_________________________
Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }

Top
#160347 - 26/09/06 01:56 AM Re: Testing while loops
Lhurgoyf3 Offline
Pikka bird

Registered: 25/09/06
Posts: 13
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
    }
  }
}

Top
#160348 - 27/09/06 09:47 PM Re: Testing while loops
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
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
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#160349 - 27/09/06 11:58 PM Re: Testing while loops
Scorpwanna Offline
Fjord artisan

Registered: 20/09/03
Posts: 261
Loc: Arkansas, US
Or just use a timer.

join #chan | .timermodeme 1 1 mode #chan -o $me
_________________________
We don't just write the scripts, we put them to the test! (ScriptBusters)

Top