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.

Help with script

Help for those learning Tcl or writing their own scripts.
Post Reply
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Help with script

Post by l.kleijn »

Code: Select all

bind pub - !money pub:money
 
proc pub:money {nick host hand chan arg} {
  global botnick
  set searchstring $arg
  set fname "money.txt"
  set fp [open $fname "r"]
  set data [read -nonewline $fp]
  close $fp
  set lines [split $data "\n"]
  set searchresult ""
  foreach line $lines {
     if {[string match * $nick* [join $line]]} {
        lappend searchresult $line
     }
     if {[$nick == "[lindex [split [join $searchresult] "|"] 0]"} {
        putserv "NOTICE $nick :Je bent al een keer hier geweest."
        return 0
     }
     putserv "NOTICE $nick :You have €[lindex [split [join $searchresult] "|"] 1]"} {
     return 0
  }
}
And i'm getting this error: [14:35:22] Tcl error [pub:money]: wrong # args: should be "foreach varList list ?varList list ...? command"
User avatar
CrazyCat
Revered One
Posts: 1217
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

In fact, you have a trouble with the following line:

Code: Select all

putserv "NOTICE $nick :You have €[lindex [split [join $searchresult] "|"] 1]"} {
The right script might be:

Code: Select all

bind pub - !money pub:money

proc pub:money {nick host hand chan arg} {
	global botnick
	set searchstring $arg
	set fname "money.txt"
	set fp [open $fname "r"]
	set data [read -nonewline $fp]
	close $fp
	set lines [split $data "\n"]
	set searchresult ""
	foreach line $lines {
		if {[string match * $nick* [join $line]]} {
			lappend searchresult $line
		}
		if {[$nick == "[lindex [split [join $searchresult] "|"] 0]"} {
			putserv "NOTICE $nick :Je bent al een keer hier geweest."
			return 0
		}
		putserv "NOTICE $nick :You have €[lindex [split [join $searchresult] '|'] 1]"
		return 0
	}
}
Think to indent your code and you'll see this kind of errors
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

Now it's working thanks
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

Now i have something else

I have a file called money.txt and there is a line called Fujin|50 and i want to remove that line with a tcl script. How do i do this ?
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Maybe check this forum thread for some procs to work with text files...
http://forum.egghelp.org/viewtopic.php?t=19168
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply