This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Help for those learning Tcl or writing their own scripts.
maphex
Voice
Posts: 9 Joined: Fri Feb 10, 2012 5:06 pm
Post
by maphex » Tue Dec 08, 2015 6:50 pm
I already have a script i'm working but part of the puzzle that i cant figure out how to do is i'm using bind cron to run the proc every so often but i want it to scan the channel list and save each user as a variable probable use a foreach and use the variable in the rest of the proc. If anyone can show me the best way yo do this would be great.
SpiKe^^
Owner
Posts: 831 Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:
Post
by SpiKe^^ » Tue Dec 08, 2015 7:15 pm
In tcl, foreach works on tcl lists, not arrays of variables like some other languages...
Code: Select all
foreach nick [chanlist #somechannel] {
## do something with each nick in the channel ##
}
maphex
Voice
Posts: 9 Joined: Fri Feb 10, 2012 5:06 pm
Post
by maphex » Tue Dec 08, 2015 9:00 pm
Worked great thanks SpiKe^^
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Wed Dec 09, 2015 10:14 am
In case you wish to exclude bot from the list you got two options:
1. Inside the
foreach loop add a
continue instruction if the nick matches bot's name by using the built-in
isbotnick function like this:
Code: Select all
foreach nick [chanlist #somechannel] {
if {[isbotnick $nick]} continue
}
2. Or better, just exclude it right away when creating the list:
Code: Select all
set userList [lreplace [chanlist #somechannel] 0 0]
foreach nick [split $userList] {
# do something with each nick in the channel
}
Once the game is over, the king and the pawn go back in the same box.
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Wed Dec 09, 2015 10:22 am
What if bot's nick is not the first one in the list returned by chanlist ?
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
SpiKe^^
Owner
Posts: 831 Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:
Post
by SpiKe^^ » Wed Dec 09, 2015 7:04 pm
willyw wrote: What if bot's nick is not the first one in the list returned by chanlist ?
Yes, I checked the chanlist return and there is no way to tell where the bots nick will be in that return...
my eggdrop return wrote: [17:11] <SpiKe^^> ;chanlist #pc-mirc-help
[17:11] <Morticia> SpiKe^^: #266 (14 clicks) Tcl: Bogustrivia bogustrivia^ Morticia RayMond kingkong Robby Howitzer SpiKe^^ ZoRoCaShE starr Starr`
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Fri Dec 11, 2015 11:22 am
Bot's name is always first, or at least is should be.
.tcl chanlist #eggdrop
Tcl: Bot Pixelz jack3 RockKeyman CRaby Stephe nrt r00tb0y Guest67864 poptix Granis` Lillypad simple Rothgar Broney Freeder_ Kamran vigilant CyBex niko_ KuNgFo0_ sid3windr add_ Biagio zeveroare FireEgl SpiKe^^ thekidd DrPepper SoulesSs Robby thommey Ratler Spike Ritche
Anyway, if you want to be 100% sure about removing it from the right position then proceed with:
Code: Select all
set userList [chanlist #somechannel]
set pos [lsearch -nocase $userList $::botnick]
set userList [lreplace $userList $pos $pos]
and continue with the
foreach loop.
Once the game is over, the king and the pawn go back in the same box.
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Fri Dec 11, 2015 1:28 pm
caesar wrote: Bot's name is always first, or at least is should be.
That's interesting.
Why?
Anyway, if you want to be 100% sure about removing it from the right position then proceed with:
Code: Select all
set userList [chanlist #somechannel]
set pos [lsearch -nocase $userList $::botnick]
set userList [lreplace $userList $pos $pos]
and continue with the
foreach loop.
Yep.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !