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.

i need basic script: !kill, !kline

Old posts that have not been replied to for several years.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

the string length is to check if the string is empty, so [split $arg] would still be recommended... or not ?
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

user wrote:I think checking $arg as the first thing inside the proc would make the most sense. Then you would avoid all that work for nothing. No need to split an empty string just to find out it's empty :)
The best way to check if a variable is empty (imo) is

Code: Select all

if {[string length $arg]} {not empty} {empty}
That's nice and all... but as in this case, we are interested in checking for TWO (2) arguments within arg... thus, if only one is set instead of two, your check would give it a pass, when it should have failed...

For this situation caesars (+users fix) would be the best answer:

Code: Select all

if {[llength [split $arg]] == 2} { ... }
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Sir_Fz wrote:the string length is to check if the string is empty, so [split $arg] would still be recommended... or not ?
'string length' is a STRING operation (hence the 'string' word)
'llength' is a LIST operation (hence the 'l' letter in front)

Given: $arg is a string

for 'llength' we need a list parameter... thus we split the string ($arg) converting it into a list.

for 'string length', $arg is already a string thus we do not need to convert it.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

so if {[llength [split $arg]] == 2} { ... } will check if the second word is empty then it will do whatever.... ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The llength check will "test" if you have specified the two arguments that are needed, that's all, so yes, basicaly it would do the trick :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Sir_Fz wrote:so if {[llength [split $arg]] == 2} { ... } will check if the second word is empty then it will do whatever.... ?
Not quite...
It will check if the length of the list is 2, implying that there are (no more than, and no less than) two non-empty elements within the [split $arg] list.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

yes but i guess the reason would be more than one element
so the user would be [lindex [split $arg] 0] and the reason would be [lrange [split $arg] 1 end] so the llength wouldn't do it in this case ?
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Sir_Fz wrote:yes but i guess the reason would be more than one element
so the user would be [lindex [split $arg] 0] and the reason would be [lrange [split $arg] 1 end] so the llength wouldn't do it in this case ?
To be honest, I wasn't really paying attention to the application, just the premise... :oops:

But yes, llength will still apply... just needs to be modded slightly...

Code: Select all

if {[llength [split $arg]] >= 2} { acceptable parameters code goes here }
(Greater than or equal to 2 param's).
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

It dosen't matter what arguments you use in order to function propertly. The [lindex [split $arg] 0] and the [lrange [split $arg] 1 end] are correct. Also, it can be equal or bigger than 2 or just equal or smaller or whatever you want, it will still work. :P
Once the game is over, the king and the pawn go back in the same box.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

ok, I got how it works now, thanx :)
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Actually, upon furthur inspection of this case, with the given data,
the llength [split $arg]] == 2 is the correct assertion, and I will explain why...

The code mentioned in this thread was:

Code: Select all

putserv "KILL $user $reason"
Now, this will result in only using word 1 from $reason to issue the kill... to have a multi-word reason, this would need to be modified to:

Code: Select all

putserv "KILL $user :$reason"
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

lol, yes you're right.. the mistake of skipping the ":" is very common :P
also if you see in the first code given "reason is set to [lindex $arg 1]" so its only 1 word too :P
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The

Code: Select all

set user [lindex [split $arg] 0]
set reason [lrange [split $arg] 1 end]
will do fine :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

caesar wrote:The

Code: Select all

set user [lindex [split $arg] 0]
set reason [lrange [split $arg] 1 end]
will do fine :)
Not without the mods mentioned in the last few posts...
quit trying to increase your post count, and read the posts :p
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Huh? What changes can be applied to this two then? And I'm not "spaming" around for posts :P
Once the game is over, the king and the pawn go back in the same box.
Locked