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 

Commands

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Mon Sep 28, 2009 8:06 pm    Post subject: Commands Reply with quote

Where can i find a list of ALL commands and the correct syntax used in a tcl
for example:-
lindex
lrange
lreplace
and how to add a line of text to a line of text
eg,
set text [lrange [split $text] 2 end] + "requested by $nick"
_________________
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
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Sep 28, 2009 9:55 pm    Post subject: Reply with quote

This thread probably belongs in the 'Scripting Help' forum

Core Tcl 8.4

http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm

Core Tcl 8.5

http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

Eggdrop 1.6.19 Tcl

http://www.eggheads.org/support/egghtml/1.6.19/tcl-commands.html

Basic Eggdrop Tcl Tutorial

http://eggdrop.org.ru/data/man/sunnet/index.html


Your string concatenation could be very simply written :-

Code:

set text "[join [lrange [split $text] 2 end]] requested by $nick"


The statement would be first parsed to make the command and variable substitutions before assigning the result to the variable text.

Exact syntax above assumes you wanted a space between the two components. Note the addition of a 'join' command to convert back to a string.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Mon Sep 28, 2009 10:12 pm    Post subject: How to add text to a line of text Reply with quote

many thanks for your quick reply

Code:
set text "[join [lrange [split $text] 2 end]] requested by $nick"

does work

I have also found that
Code:
set text [lrange [split $text] 2 end]
lappend text :Requested by $nick

also works
found that merged with other stuff in "tip of the day"
_________________
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
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Sep 28, 2009 10:31 pm    Post subject: Reply with quote

Yes, that would work fine.

However, be careful. In your code, the variable text started life as a string but it is now a list.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Mon Sep 28, 2009 10:42 pm    Post subject: Reply with quote

whilst reading the url http://eggdrop.org.ru/data/man/sunnet/index.html


i've found another method (so easy)
Code:

   set text [lrange [split $text] 2 end]
   set text "$text :requested by $nick"


seems like one minute nothing works, the next minute three options work
_________________
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
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Tue Sep 29, 2009 10:24 am    Post subject: Reply with quote

It is quite common to find several ways to accomplish the exact same thing. This would be true to some degree of any programming/scripting language.

However, not wishing to seem a bore, I do get the impression that you are not taking in what I am trying to communicate regarding the difference between strings and string lists.

A better understanding of these data structures can save you many problems in the future, though I can say that I do still make such mistakes (such is the ease with which they sometimes get confused).

Taking your latest code example apart :-

Code:

set text [split $text]


Although it cannot be confirmed by simply looking at the statement above, it does give the impression that the original value of the variable text is a string, because it is being split to form a list. The set command overwrites the original string value of text with the list value. Given that it is now a list, you can safely use list commands such as lrange on it :-

Code:

set text [lrange [split $text] 2 end]


Indices for lrange (and other commands) start at zero, so the above statement makes a new list from the 3rd element onwards of text and again overwrites the value of text with this new list. It is STILL a list.

Code:

set text [lrange [split $text] 2 end]
set text "$text :requested by $nick"


This is potentially where things could all go pear shaped. The second statement may well succeed on occasions in generating what you need, yet it does create something that may not have been anticipated. The new list value of text has had string characters attached to it.

There are really two ways to go. Firstly if you want to end up with a normal string :-

Code:

set text [join [lrange [split $text] 2 end]]
set text "$text :requested by $nick"


This is probably the best because it ensures that the value of text is in the same form as it was in the first place. The join command has been used in the first statement to convert the lrange result back into a string. Hence, the second statement simply adds additional characters to form a longer string.

The join command could be alternatively placed as follows :-

Code:

set text [lrange [split $text] 2 end]
set text "[join $text] :requested by $nick"


Secondly, If you definitely need the result to be a list, then you first need to determine if the three words included in ':requested by $nick' are to be three distinct list elements or one single list element. These are the two possibilities :-

Code:

set text [lrange [split $text] 2 end]
lappend text :requested by $nick


Code:

set text [lrange [split $text] 2 end]
lappend text ":requested by $nick"


In reality the problem can get rather more complicated because lists of list and lists of lists of lists etc etc are permitted. That means that the join command wouldn't necessarily create a string. It may create a 'flatter' list. To be fair I would forget this added difficulty until you are confident with the simple case (a normal string OR a flat list of string elements).

Some insight into the sort of problems that can occur can be gained by reading :-

http://www.peterre.info/characters.html
_________________
I must have had nothing to do
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 -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
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