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.

Question to a script...

Old posts that have not been replied to for several years.
Locked
s
sceada

Question to a script...

Post by sceada »

Hi !

I have a Problem with a search script i`ve written...
I have the script with different commands and urls, but i use only one of them here to explain you my Problem.
(this bot is for a bot in a channel where we talk about Magic the Gathering..)

The script:
bind pub - .info infosearch

proc infosearch { nick uhost hand chan args } {
putchan $chan http://magiccards.info/query.php?cardname=$args
}

This works fine, if there is only 1 keyword to search:
(@sceada) .info Lotus
(@|magicbot|) http://magiccards.info/query.php?cardname=Lotus

But now my Problem:
when there are 2 Words, it doesnt work :
(@sceada) .info Black Lotus
(@|magicbot|) http://magiccards.info/query.php?cardname={Black Lotus}

But i want the Bot to give out the 2 Words with an "_" between...
(http://magiccards.info/query.php?cardname=Black_Lotus)

how can i make this ?
(or even for more words...)

(im sorry for my bad english, but i`m from Austria...)
mfg, sceada
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Well use something like this.
Replace the variable $args with $text or $arg as $args in tcls stands for a list, and it is showing your variables in a list structure with the { }.

Example:
set mynames { "james" "lewis" "jessica" "dave" "michael" }

Code: Select all

set newvar "[lindex $text 0]_[lindex $text 1]"
#This should make them in the form "$var1_$var2"

#or on your current settings you can do
set newvar [join $var {_}] 
#where $var is the list being shown as {Black Lotus}
If you want to do it for "N" variables then you would need to do a for loop and incr value one at a time for each lindex in $text and lappend all the variables in a new list and then join with {_}.

Something like this: (not tested)

Code: Select all

set variables [list]
set textlength [expr [llength $text] - 1]
 for {set i 0} {$i < $textlength} {incr i} {
  if {([lindex $text $i] != "")} { 
   lappend variables [lindex $text $i]
   }
  }
  if {($variables != "")} { set variables [join $variables {_}] }
  #Then go ahead and do your stuff with $variables and display them.
Alternatively, you can also use concat.
See the tcl manual for commands such as join, concat, lappend, append etc. :mrgreen:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
s
sceada

Post by sceada »

Thank you very much !

my script is not working at the moment, but im working on it :D
im new in Tcl, so i will read some manuals, and i hope then i can bind your code into my script :lol:

but now i have a base, and know how it can work, so i thing i should be able to make it :D

greets, sceada
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Good luck!
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked