egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

"Tip of the day"
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ
View previous topic :: View next topic  
Author Message
slennox
Owner


Joined: 22 Sep 2001
Posts: 593

PostPosted: Tue May 03, 2005 12:46 pm    Post subject: "Tip of the day" Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
^DooM^
Owner


Joined: 26 Aug 2003
Posts: 772
Location: IronForge

PostPosted: Tue May 03, 2005 6:11 pm    Post subject: split Reply with quote

When using
Code:
[lindex $arg 0]
always make sure you use split to properly deal with your list.
Code:
[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
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue May 03, 2005 7:07 pm    Post subject: Reply with quote

Same goes with
Code:
[lrange $arg 0 end]

use this instead
Code:
[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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts


Last edited by Sir_Fz on Fri Jan 05, 2007 7:50 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu May 05, 2005 7:00 pm    Post subject: Reply with quote

To get the host from $uhost (ident@host) you can use the following:
Code:
set host [lindex [split $uhost @] 1]

Now you can use *!*@$host as a banmask.

Or you can use:
Code:
scan $uhost %*\[^@\]@%s host

Which will also assign the host to $host.

To get both ident and host, you can use:
Code:
scan ident@host %\[^@\]@%s ident host

Now you have the ident in $ident and the host in $host.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Fri May 06, 2005 11:31 am    Post subject: naming eggdrop.conf Reply with quote

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.
Back to top
View user's profile Send private message
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Fri May 06, 2005 11:33 am    Post subject: looking for bugs Reply with quote

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.
Back to top
View user's profile Send private message
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Fri May 06, 2005 11:34 am    Post subject: looking for server replies Reply with quote

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.
Back to top
View user's profile Send private message
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Fri May 06, 2005 11:37 am    Post subject: What on earth is this variable Reply with quote

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)
Back to top
View user's profile Send private message
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Fri May 06, 2005 11:38 am    Post subject: now how can i shorten this tcl Reply with quote

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
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri May 06, 2005 11:43 am    Post subject: Reply with quote

Use proper formatting while writing a code so you won't get lost in it.
for example:
Code:
if {[botisop $chan]} {
 if {$nick == "bla"} {
  pushmode $chan +v $nick
 }
}

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

This way you'll find it easier to trace the open and closed braces.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
greenbear
Owner


Joined: 24 Sep 2001
Posts: 733
Location: Norway

PostPosted: Fri May 06, 2005 7:09 pm    Post subject: Reply with quote

get rid of the redundant braces, and it'll be even easier to read Rolling Eyes
Code:
if [botisop $chan] {
 if {$nick == "bla"} {
  pushmode $chan +v $nick
 }
}
Back to top
View user's profile Send private message Send e-mail
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri May 06, 2005 7:57 pm    Post subject: Reply with quote

Or even better you can combine those 2 if statements in one:
Code:
if {[botisop $chan] && $nick == "bla"} {
  pushmode $chan +v $nick
}

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

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun May 08, 2005 8:32 pm    Post subject: Reply with quote

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:
set mylist [list nick1 nick2 nick3 nick4]

set mylist [join $mylist ,]

# Now, $mylist will return: nick1,nick3,nick3,nick4.

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat May 14, 2005 7:16 pm    Post subject: Reply with quote

You can use different commands to send data into server.

The fastest way is by using:
Code:
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)

Quote:
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

Quote:
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

Quote:
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 Razz

PS: RTFM (^DooM^'s popular acronym Razz )
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Sun May 15, 2005 9:48 am    Post subject: reading help files Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ All times are GMT - 4 Hours
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber