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.

"Tip of the day"

Issues often discussed about Tcl scripting. Check before posting a scripting question.
User avatar
slennox
Owner
Posts: 593
Joined: Sat Sep 22, 2001 8:00 pm
Contact:

"Tip of the day"

Post by slennox »

This topic is for the posting of scripting tips, i.e. short pieces of advice rather than major concepts. It was requested by NoZparker who would like to pass on things he comes across while learning Tcl, but anyone can share their tips here.
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

split

Post by ^DooM^ »

When using

Code: Select all

[lindex $arg 0]
always make sure you use split to properly deal with your list.

Code: Select all

[lindex [split $arg] 0]
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Same goes with

Code: Select all

[lrange $arg 0 end]
use this instead

Code: Select all

[join [lrange [split $arg] 0 end]]
Split is used to turn the string $arg into a list since lrange is applied to lists, and join converts it back to a string. (check out http://www.peterre.info/characters.html)

Edit: Updated URL to the new one.
Last edited by Sir_Fz on Fri Jan 05, 2007 7:50 pm, edited 1 time in total.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

To get the host from $uhost (ident@host) you can use the following:

Code: Select all

set host [lindex [split $uhost @] 1]
Now you can use *!*@$host as a banmask.

Or you can use:

Code: Select all

scan $uhost %*\[^@\]@%s host
Which will also assign the host to $host.

To get both ident and host, you can use:

Code: Select all

scan ident@host %\[^@\]@%s ident host
Now you have the ident in $ident and the host in $host.
N
NoZparker
Voice
Posts: 34
Joined: Mon Feb 16, 2004 6:07 am

naming eggdrop.conf

Post by NoZparker »

Whilst saving an eggdrop.conf use all lower case. This will not effect the nickname of the bot but does save time looking in the dir to remember how you have saved the conf when it's crashed, and you have to restart.
N
NoZparker
Voice
Posts: 34
Joined: Mon Feb 16, 2004 6:07 am

looking for bugs

Post by NoZparker »

When you are looking for a bug in your new tcl that you are writing and is not necessarily an error use.... Putlog "got this far" .....in the tcl. and then move it so you can see what is happening.
N
NoZparker
Voice
Posts: 34
Joined: Mon Feb 16, 2004 6:07 am

looking for server replies

Post by NoZparker »

If you need to see the result of perhaps a server notice or what the bot sees in channel while you are writing your tcl then set ... .console [channel] +r. ....but don't forget to turn it off.
N
NoZparker
Voice
Posts: 34
Joined: Mon Feb 16, 2004 6:07 am

What on earth is this variable

Post by NoZparker »

Whilst writing a tcl use long discription variables. That makes it easier to follow. Then when you are finished replace with shortened variables. (keep it small)
N
NoZparker
Voice
Posts: 34
Joined: Mon Feb 16, 2004 6:07 am

now how can i shorten this tcl

Post by NoZparker »

when you have finished writing a tcl, or think you have finished. look for if's inside of if's. eg
if {1st set of rules} {
if {2nd set of rules} {
do your stuff
}
}
can be written
if {(1st set of rules) && (2nd set of rules)} {
do your stuff
}

--------------- save space
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Use proper formatting while writing a code so you won't get lost in it.
for example:

Code: Select all

if {[botisop $chan]} {
 if {$nick == "bla"} {
  pushmode $chan +v $nick
 }
}
is more clear and easier to follow than:

Code: Select all

if {[botisop $chan]} {
if {$nick == "bla"} {
pushmode $chan +v $nick
}
}
This way you'll find it easier to trace the open and closed braces.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

get rid of the redundant braces, and it'll be even easier to read :roll:

Code: Select all

if [botisop $chan] {
 if {$nick == "bla"} {
  pushmode $chan +v $nick
 }
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Or even better you can combine those 2 if statements in one:

Code: Select all

if {[botisop $chan] && $nick == "bla"} { 
  pushmode $chan +v $nick 
}
or as gb may prefer:

Code: Select all

if [botisop $chan]&&[string equal "bla" $nick] {
 pushmode $chan +v $nick
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

If you want to join a list with a special character, like for example "nick1 nick2 nick3 nick4" to "nick1,nick2,nick3,nick4" you can use this:

Code: Select all

set mylist [list nick1 nick2 nick3 nick4]

set mylist [join $mylist ,]

# Now, $mylist will return: nick1,nick3,nick3,nick4.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You can use different commands to send data into server.

The fastest way is by using:

Code: Select all

putdccraw 0 [string length "YOUR DATA\n"] "YOUR DATA\n"
# for example:
# putdccraw 0 [string length "MODE $chan +b $ban\n"] "MODE $chan +b $ban\n"
But be carefull using this since it might flood out your bot.

Then we have eggdrop's queues (fastest to slowest order)
putquick <text> [options]
Description: sends text to the server, like 'putserv', but it uses a
different (and faster) queue.
Options:
-next: push messages to the front of the queue
-normal: no effect
Returns: nothing
Module: server
putserv <text> [options]
Description: sends text to the server, like '.dump' (intended for direct
server commands); output is queued so that the bot won't flood itself
off the server.
Options:
-next: push messages to the front of the queue
-normal: no effect
Returns: nothing
Module: server
puthelp <text> [options]
Description: sends text to the server, like 'putserv', but it uses a
different queue intended for sending messages to channels or people.
Options:
-next: push messages to the front of the queue
-normal: no effect
Returns: nothing
Module: server
I figured alot don't take a look at Tcl-commands.doc, so reading the quotes might be better for them :P

PS: RTFM (^DooM^'s popular acronym :P )
N
NoZparker
Voice
Posts: 34
Joined: Mon Feb 16, 2004 6:07 am

reading help files

Post by NoZparker »

when you looking for answers sometimes it is worth looking in the help file in your mirc script (looking for correct syntax maybe) as well as in the tcl-commands.doc (found in the eggdrop\doc folder
Oh and don't forget to do a search here in the forum
It's times like this I wished I had listened to What my dad used to say. Can't say what it was I never listened.
Post Reply