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.

Getall nicknames in channel

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

caesar, I think it is possible to use alternative syntax in any programming/scripting languages to achieve the same goal. Nonetheless, thank you for the interesting alternatives.

Out of interest, how would you remove $botnick from the channel list? As far as I can see the lsearch command is there to determine where it is in the list in order to facilitate removal, rather than merely whether or not it is there.
I must have had nothing to do
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Sure, but if you can make things run faster at a lower resources consumption, why not?

I've said "proceed to remove it from the list" as in remove the if check statement as it will always return true, not in using another method if that's what you imply. :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Thanks caesar, I did understand your intent in posting alternatives. My response was borne of your terminology 'you should use' whereas it might have been better to say 'you could use' or 'consider instead using'. I didn't want other readers to misinterpret your remarks and perhaps believe the script posted by Get_A_Fix is somehow disfunctional. As far as I can tell it is absolutely fine. I certainly hope so, since I contributed to it.

You wrote :-

Code: Select all

if {[scan $text %s channel] != 1} {
I think you meant :-

Code: Select all

if {[scan $text %s channel] == 1} {
I suppose you could consider rewriting the existing variable rather than creating another :-

Code: Select all

if {[scan $text %s text] == 1} {
This is still not exactly equivalent to the existing code. It will not fail if more than one command argument is provided. Rather, it will rewrite the value of text with the first of the arguments, presuming that is what the command user intended. A perfectly fair assumption but I suppose it depends what the author prefers.

You wrote (replacing $channel with $text as per above) :-

Code: Select all

if {[string equal -length 1 # $text]} {
I like this code very much and might adopt it. Just shows the benefit in looking more closely at command switches/options.

Finally, the 'if' statement is a way of removing $botnick in one uninterrupted statement. If I'm not mistaken it would otherwise require two disparate statements. One to find the list index, then another to remove it. This is not an important point, except if I was to generalize for the benefit of other readers and say that code elements often contain seemingly superfluous statements, yet are deliberate.
I must have had nothing to do
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Actually, it should have been:

Code: Select all

if {[scan $text %s channel]} { 
cos $test is equal with 1 then a if {$test} { true as in equal or bigger than 1 } and if {!$test} { true as in equal with 0 }

To be honest I find scan usefull if for instance I have 3 variables I want to extract from a user input, so with scan is just as simple as:

Code: Select all

if {[scan $text %s%s%s first second third] == 3} {
that's equal with:

Code: Select all

set text [split $text]
if {[llength $text] == 3} {
	set first [lindex $text 0]
	set second [lindex $text 1]
	set third [lindex $text 2]
}
notice how easy is with scan to do about the same thing. :) I'd have to say thanks to user, cos I learned this trick from him. :)

Code: Select all

if {[set bot [lsearch $nicklist $botnick]] != -1} {set nicklist [lreplace $nicklist $bot $bot]} 
you don't need a if statement as it will always return true. I meant to change it to:

Code: Select all

set bot [lsearch $nicklist $botnick]
set nicklist [lreplace $nicklist $bot $bot]
Once the game is over, the king and the pawn go back in the same box.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I'm unsure of your code caesar :-

Code: Select all

if {[scan $text %s channel]} {
If the command user mistakingly fails to input any command arguments, then scan will return -1 yet, when used in this way, any non-zero value is considered true. Hence the code inside the if statement may attempt execution, whereas it should not have. Am I correct in my assessment?

This discussion does give me an idea though. Generally, I concern myself with preventing users accidentally or deliberately inputting things that may break a script. This is what I might use normally :-

Code: Select all

set text [regsub -all -- {\s{2,}} [stripcodes bcruag [string trim $text]] " "]
if {[llength [split $text]] == 1} {
Quite ugly.

What about this :-

Code: Select all

if {[scan [stripcodes bcruag $text] %s%s text dummy] == 1} {
Seems to kill several birds with one stone

1. No need to trim $text or convert double spaces between words to one space
2. Fails if the user inputs zero command arguments
3. Fails if the user inputs more than one command argument
4. Is half the number of lines of code
5. Uses scan to make my ugly code more efficient

On the subject of the if/lsearch issue I do think we are still on different wavelengths. I tried to explain that I only used it to construct a single code element, rather than actually determine whether the botnick is present in the list. As you point out, it always is. We both agree that without it, two seperate statements are required. Admittedly, on the subject of code efficiency it may be better to have two seperate statements.
I must have had nothing to do
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Oups, my bad. Forgot about -1 return when there's nothing to be scanned.
About:

Code: Select all

if {[scan [stripcodes bcruag $text] %s%s text dummy] == 1} { 
well, if the user will say two or multiple words the scan will return:

Code: Select all

% set text "word1 word2 word3"
word1 word2 word3
% scan $text %s%s first second
3
% echo $first
word1
% echo $second
word2
notice that it stored in the second variable only the second word, not second and third word.
Once the game is over, the king and the pawn go back in the same box.
Post Reply