mIRC -> Tutorials -> 05
I wasn't really sure what to do next for my tutorial but then someone asked me
about while loops so here you go :)
First a simple example to give you the basics.
set %i 1
while (%i < 10) {
echo while loop: %i
inc %i
}
That's it! While loops are very very easy to both code and use. First you set a variable
to a value (in this case we give %i the value 1), then we tell mIRC "how" it should loop
(as long as the value of %i is below 10) and what it should do when it loops (echo the
%i value and increase it with one).
They're also very dynamic so you can put pretty much anything you want inside the loop
condition ($lines, $ctime, variables, $read) and it will work. Two more examples, one
easy on how to integrate the above code with an on text event and a more advanced one
(use the helpfile luke).
on *:text:!while*:#:{
set %i 1
while (%i < $2) {
msg $chan looping... %i
inc %i
}
}
massop {
var %i = 1
while (%i <= $nick($1,0,a,o)) {
mode $chan +oooooo $nick($1,%i,a,o) $nick($1, $calc(%i + 1),a,o) $nick($1, $calc(%i + 2),a,o) $nick($1, $calc(%i + 3),a,o) $nick($1, $calc(%i + 4),a,o) $nick($1, $calc(%i + 5),a,o)
inc %i 6
}
}
Not a lot changed there, not a lot to change. As I said, while loops are extremely easy
and very powerful. You tell it "do this until A equals B" and it does just that. One
important thing: dont forget the "inc %i" command because otherwise mIRC will keep
looping until %i reaches 10...which it of course never will.
The massop alias looks more complicated but it's very easy too, you type "/massop #channel"
and it will op everyone who doesnt have op on the channel. %i is set to 1, and as long as
%i is lower than all the people on the channel without op ($chan(#chan,0,a,o)) it will loop
giving op to six people at a time. Look carefully at the code, see how $nick works and play
a little with it. Go code! :)
BTW, if you're used to programming before you can also use a for-loop ala C++ if you feel
more at home with that. Personally I think while-loops are easier to read and write.