mIRC Home    About    Download    Register    News    Help

Print Thread
Testing while loops #160339
25/09/06 07:18 PM
25/09/06 07:18 PM
Joined: Sep 2006
Posts: 13
L
Lhurgoyf3 Offline OP
Pikka bird
Lhurgoyf3  Offline OP
Pikka bird
L

Joined: Sep 2006
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?

Re: Testing while loops #160340
25/09/06 07:30 PM
25/09/06 07:30 PM
Joined: Aug 2005
Posts: 1,052
Canada
L
Lpfix5 Offline
Hoopy frood
Lpfix5  Offline
Hoopy frood
L

Joined: Aug 2005
Posts: 1,052
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

Re: Testing while loops #160341
25/09/06 07:34 PM
25/09/06 07:34 PM
Joined: Sep 2006
Posts: 13
L
Lhurgoyf3 Offline OP
Pikka bird
Lhurgoyf3  Offline OP
Pikka bird
L

Joined: Sep 2006
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.

Re: Testing while loops #160342
25/09/06 07:39 PM
25/09/06 07:39 PM
Joined: Aug 2005
Posts: 1,052
Canada
L
Lpfix5 Offline
Hoopy frood
Lpfix5  Offline
Hoopy frood
L

Joined: Aug 2005
Posts: 1,052
Canada
yeah your right

my bad


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Testing while loops #160343
25/09/06 07:40 PM
25/09/06 07:40 PM
Joined: Sep 2003
Posts: 261
Arkansas, US
S
Scorpwanna Offline
Fjord artisan
Scorpwanna  Offline
Fjord artisan
S

Joined: Sep 2003
Posts: 261
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)
Re: Testing while loops #160344
25/09/06 07:42 PM
25/09/06 07:42 PM
Joined: Sep 2003
Posts: 261
Arkansas, US
S
Scorpwanna Offline
Fjord artisan
Scorpwanna  Offline
Fjord artisan
S

Joined: Sep 2003
Posts: 261
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)
Re: Testing while loops #160345
25/09/06 07:45 PM
25/09/06 07:45 PM
Joined: Sep 2006
Posts: 13
L
Lhurgoyf3 Offline OP
Pikka bird
Lhurgoyf3  Offline OP
Pikka bird
L

Joined: Sep 2006
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)

Re: Testing while loops #160346
25/09/06 09:53 PM
25/09/06 09:53 PM
Joined: Aug 2005
Posts: 1,052
Canada
L
Lpfix5 Offline
Hoopy frood
Lpfix5  Offline
Hoopy frood
L

Joined: Aug 2005
Posts: 1,052
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* }
Re: Testing while loops #160347
26/09/06 12:56 AM
26/09/06 12:56 AM
Joined: Sep 2006
Posts: 13
L
Lhurgoyf3 Offline OP
Pikka bird
Lhurgoyf3  Offline OP
Pikka bird
L

Joined: Sep 2006
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
    }
  }
}

Re: Testing while loops #160348
27/09/06 08:47 PM
27/09/06 08:47 PM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
jaytea  Offline
Fjord artisan
J

Joined: Feb 2006
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
Re: Testing while loops #160349
27/09/06 10:58 PM
27/09/06 10:58 PM
Joined: Sep 2003
Posts: 261
Arkansas, US
S
Scorpwanna Offline
Fjord artisan
Scorpwanna  Offline
Fjord artisan
S

Joined: Sep 2003
Posts: 261
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)