SUNiNET - Your Eggdrop & TCL resources site
[ Home Eggdrop TCL Links About ]

Guide to TCL scripting for Eggdrop 1.6


[ Previous ] [ Index ] [ Next ]


10.1 Looping under conditions

The most basic loop is the while loop.
This will keep going until a set of given actions match each other. The while command also looks a lot like the if command.
The syntax of a while command is while { <check> } { <body> }.

The <check> works in exactly the same way as the if command.
It's possible to simply replace "while" with "if" and make the script execute the set of commands only once without running into any errors except for ones that come from your script, but not from the while command itself.

The <body> is also just like in the if command and is the set of commands you want the loop to execute while it's running.

Here is an example of a while loop:

set test "[chanlist #eggdrop]"
set ops 0
while {$test != ""} {
  if {[isop [lindex $test 0] #eggdrop]} {
    incr ops
  }
  set test "[lreplace $test 0 0]"
}
puthelp "PRIVMSG #eggdrop :There are currently $ops people opped in #eggdrop."


[ Previous ] [ Index ] [ Next ]


Design & Graphics by Shawn Borton
Copyright © 2000-2005 Marijn van Zon