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.

Need Help with Userlist

Help for those learning Tcl or writing their own scripts.
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

nvm
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

why wont it work

Post by theice »

Code: Select all

if {([lindex [split $t] 2] == "") && ([lindex [split $t] 1] == "XBox") || ([lindex [split $t] 1] == "PS3")} {
^wont work

whereas:

Code: Select all

if {[lindex [split $t] 1] == ""} {
^will

trying to say if line 2 == BLANK and line 1 is either XBox or PS3 do this!
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: why wont it work

Post by speechles »

theice wrote:

Code: Select all

if {([lindex [split $t] 2] == "") && ([lindex [split $t] 1] == "XBox") || ([lindex [split $t] 1] == "PS3")} {
^wont work

whereas:

Code: Select all

if {[lindex [split $t] 1] == ""} {
^will

trying to say if line 2 == BLANK and line 1 is either XBox or PS3 do this!
This is beginning to sound like some sort of echo/pre/warez script to me. But before we address that, your mistaking how lindex works. lindex is short for list index, and works similar to how lrange does. To get each line, its better to use a [split $t \n] with a foreach.

Now to address the warez aspect, thats more than likely all the help you will get as this is going to be used it seems for piracy... ;/
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

it is not a warez script.

it is a rockband script, that will allow users to search for other users in their type of game.

Code: Select all

putserv "NOTICE $n :\002Syntax error:\002 please use (.search console [XBox/PS3] [Guitar/Bass/VoX/Drums] [Easy/Medium/Hard/Expert]) ie \002.search console PS3 VoX Expert\002"
that is a line from the code, I have everything working 100% so far minus I can't get that ONE line to work:

Code: Select all

if {([lindex [split $t] 2] == "") && ([lindex [split $t] 1] == "XBox") || ([lindex [split $t] 1] == "PS3")} {
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

theice wrote:it is not a warez script.

it is a rockband script, that will allow users to search for other users in their type of game.

Code: Select all

putserv "NOTICE $n :\002Syntax error:\002 please use (.search console [XBox/PS3] [Guitar/Bass/VoX/Drums] [Easy/Medium/Hard/Expert]) ie \002.search console PS3 VoX Expert\002"
that is a line from the code, I have everything working 100% so far minus I can't get that ONE line to work:

Code: Select all

if {([lindex [split $t] 2] == "") && ([lindex [split $t] 1] == "XBox") || ([lindex [split $t] 1] == "PS3")} {
what is the contents of $t ?

if its multiple lines with <carriage returns> your going about it completely wrong and fail to understand how lindex works. It isnt line index, it is list index. When you split without a paramter, which [split $t] does, it makes a list of words. [lindex [split $t] 2] = the 3rd word ([lindex [split $t] 0] would be the 1st), not the 2nd line of the file as you mistakenly believe. For you to get better help, perhaps paste some of the actual script that needs fixing, or at the very least what contents $t is holding....
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

$t == $text [said by the user in the channel]
im dumb and use shorten var

in this example its said in channel:

.search console PS3
or/
.search console XBox

I want it so if someone types:
.search console XBox BLAHHHHH

it gives them the error at the } else { at the bottom instead of allowing that if statement to work.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

set consoles [split "xbox ps3"]
set difficulties [split "easy medium hard expert"]
if {[llength [split $t]] != 2 || [lsearch -exact $consoles [string tolower [lindex [split $t] 0]]] < 0 || [lsearch -exact $difficulties [string tolower [lindex [split $t] 1]]] < 0} {
    putserv "NOTICE $n :\002Syntax error:\002 please use (.search console [XBox/PS3] [Guitar/Bass/VoX/Drums] [Easy/Medium/Hard/Expert]) ie \002.search console PS3 VoX Expert\002"
} else {
    set console [lindex [split $t] 0]
    set difficulty [lindex [split $t] 1]
    # rest of script goes here
}

##no-word-wrap#####################################################################################################################################################################
most of the credit for that code snippet to nml375 (used earlier today in a diff thread)
Last edited by speechles on Fri Mar 14, 2008 3:59 am, edited 1 time in total.
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

what i need is a line that will work:

Code: Select all

if {([whatever == blankline]) && ([lindex [split $t] 1] == "XBox") || ([lindex [split $t] 1] == "PS3")} {
#morecodehere
so that way will only do the things #morecodehere if
someone types .search console XBox or .search console PS3

I know how to make it so it only works if they type those, but I want to make it so people can't type more stupid stuff after the third word PS3/XBox

confusing?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

theice wrote:what i need is a line that will work:

Code: Select all

if {([whatever == blankline]) && ([lindex [split $t] 1] == "XBox") || ([lindex [split $t] 1] == "PS3")} {
#morecodehere
so that way will only do the things #morecodehere if
someone types .search console XBox or .search console PS3

I know how to make it so it only works if they type those, but I want to make it so people can't type more stupid stuff after the third word PS3/XBox

confusing?
edited post above to be exact same thing, do you understand this at all?
Last edited by speechles on Fri Mar 14, 2008 4:16 am, edited 2 times in total.
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

no you are just confusing me. sorry I don't think you understand the way im trying to do it =[ I'm ONE line away from it being perfect, and can't figure it out.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

theice wrote:no you are just confusing me. sorry I don't think you understand the way im trying to do it =[ I'm ONE line away from it being perfect, and can't figure it out.
HAW.. I totally understand how you want to do it. :P

Code: Select all

set consoles [split "xbox ps3"]
set styles [split "guitar bass vox drums"]
set difficulties [split "easy medium hard expert"]
if {[llength [split $t]] != 3 || [lsearch -exact $consoles [string tolower [lindex [split $t] 0]]] < 0 || [lsearch -exact $styles [string tolower [lindex [split $t] 1]]] < 0 || [lsearch -exact $difficulties [string tolower [lindex [split $t] 2]]] < 0} {
    putserv "NOTICE $n :\002Syntax error:\002 please use (.search console [XBox/PS3] [Guitar/Bass/VoX/Drums] [Easy/Medium/Hard/Expert]) ie \002.search console PS3 VoX Expert\002"
} else {
    set console [string tolower [lindex [split $t] 0]]
    set style [string tolower [lindex [split $t] 1]]
    set difficulty [string tolower [lindex [split $t] 2]]
    # rest of script goes here
}


##no-word-wrap#################################################################################################################################################################################################################################################################
The above code, stores your search terms you want to appear in lists above. Clearly you see this. First we check list length, if it isnt 3 they fudged up. Next we use lsearch to check our search term lists against the users split input using their positions against this list, if we don't find it trigger the message. It's very simple. This works.

PS. What I'm trying to tell you, is your more than one line away from doing it. This is how you do it elegantly, allowing you to easily change those lists to accept less or more terms. Hard coding them is messy.
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

change of subject;

is if {[lindex [split $t] 3] == "Whatever"} {

always case-sensitive?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

theice wrote:change of subject;

is if {[lindex [split $t] 3] == "Whatever"} {

always case-sensitive?
yes, use

Code: Select all

if {[string tolower [lindex [split $t] 3]] == "whatever"} {
instead, in effect becoming case insensitive..or even

Code: Select all

if {[string equal -nocase [lindex [split $t] 3] "whatever"]} {
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

whats the difference?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Execution time. The example using == takes longer.
Post Reply