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.

!map

Help for those learning Tcl or writing their own scripts.
Post Reply
K
Kuukkeli
Voice
Posts: 4
Joined: Sun Apr 23, 2006 12:53 pm

!map

Post by Kuukkeli »

Hi, this script finds map @ kartta.dat file.

Code: Select all

bind pub - !kartta pub_kartta

proc pub_kartta { nick uhost hand chan args } {
global kartta_db
set kartta_db "data/kartta.dat"
   set args [split [lindex $args 0] " "]
    if {$args == ""} { puthelp "PRIVMSG $chan :$nick !kartta <hakusana> ohjeet: hakusanan tulee olla kolme merkkiä pitkä tai pitempi, eikä siinä saa käyttää$
return
}
    if {$args == "kz"} { puthelp "PRIVMSG $chan :$nick !kartta <hakusana> ohjeet: hakusanan tulee olla kolme merkkiä pitkä tai pitempi, eikä siinä saa käytt$
return
}
    set explain [string tolower [lindex $args 0]]
 set chan [string tolower $chan]
 set init_t [clock clicks -milliseconds]
 set fp [open $kartta_db r]
set matches ""
set allEntrys ""
 while {![eof $fp]} {
  gets $fp curEntry
if {[info exists curEntry]&&$curEntry!=""} {
   set curEntry [split [string tolower $curEntry] " "]
 set thisEntry [join [lrange $curEntry 0 end] " "]
   if { [string match -nocase "*${args}*" $thisEntry] } {
    if { [lsearch $allEntrys [lindex curEntry 1]]==-1 } {lappend allEntrys [lrange $thisEntry 0 end]
 set allEntrys [lsort -unique $allEntrys]
}
 } } }
set init_t [expr double(([clock clicks -milliseconds] - $init_t))/1000]
 if {$allEntrys==""} { puthelp "PRIVMSG $chan :Karttaa ei löytynyt."
 } else {
  if {[llength $allEntrys]>5} {puthelp "PRIVMSG $chan :Liian monta karttaa löytyi, kokeille muulla hakusanalla."
  } else {
set jee1 "[lrange $allEntrys 0 1]"
puthelp "PRIVMSG $chan :Löytyi [llength $allEntrys] kartta(a). $allEntrys"
  }

}

}
It works, but answer is [@Romuloota] Löytyi 1 kartta(a). {lol - http://asd.com/lol.asd}. How i delete these {}. Sry my bad english, i hope you understand.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Simply, use lists and strings properly. Specially, when printing the contents of allEntrys, convert it to a string ({} are used to set the boundaries for each list-item).
Something like:

Code: Select all

join $allEntrys ", "
should do the trick...

Also, don't use "args" as a parameter name when building procs, as this one is interpreted in a special fashion (allows dynamic number of arguments to be supplied to a process, each argument will be a list-item in "args"). Pub-binds will call the associated function with a fixed number of arguments, so there's no need for it here.. And frankly, your mangling of args in the code really does'nt make much sense either.
NML_375
K
Kuukkeli
Voice
Posts: 4
Joined: Sun Apr 23, 2006 12:53 pm

Post by Kuukkeli »

Now it say Tcl error [pub_kartta]: invalid command name "lol - http://asd.com/lol.asd". :S
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Then you've most likely got a pair of [] to many
NML_375
Post Reply