| Basics | Variables | Ifs | Loops | Read/Write | Raws |
Loops
While
These simply keep doing something while the expression in the brackets is true. for example
on *:TEXT:say * times:#:{
  var %a 1
  while (%a <= $3) {
  msg $chan $2
  inc %a 1
  }
}

Now when someone types "say anything 5 times" you would message the channel with "anything" 5 times
That is a pretty crap and pointless script that you will never use but you can use them for some useful things such a power scripts:
on *:TEXT:!power:#:{
  var %a 1
  var %b 0
  while (%a <= $chan(0)) {
    if ($me isop ($chan(%a)) { inc %b $nick($chan(%b),0) }
    inc %a 1
  }
  msg $chan I am on $chan(0) channels and have power over %b people
}

$chan(0) simple shows how many channels u are on, $chan(1) shows you your first channel, $chan(2) is 2nd and so on, so as %a just cycles though all your channels. $nick(#sgt,0) will show the number of people on the channel #sgt. Since $chan(1) is just your first channel you can put them both together to get $nick($chan(%a),0).
This may seem rather complex now but if u just read over it a few times you should understand it.

Goto
This is another way of doing loops, you label a particular place in a script then u can make the scripting jump to different parts to perform certain things.
on *:TEXT:!power:#:{
  var %a 0
  var %b 0
  inc %a 1
  :loop
  if ($me isop $chan(%a) { inc %b $nick($chan(%a),0) }
  if (%a == $chan(0)) { goto end }
  goto loop
  :end
  msg $chan I am on $chan(0) channels and have power over %b people
}

I myself prefer the while loop's but allot of people seem to struggle with them, try them both and see which one suits you best

NOTE:If you ever forget to put an inc %a or increment whatever variable you use then you will be trapped in a loop which will go round forever, to stop this simple press ctrl+break and it will abort the script



| Basics | Variables | Ifs | Loops | Read/Write | Raws |

If you have any comments about this tutorial please mail me here with the page and the problem.

Page counter

This site and its content is copywrite © SGT 2002 all rights reserved