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 for those learning Tcl or writing their own scripts.
QQleQ
Voice
Posts: 14 Joined: Mon Nov 20, 2006 10:05 pm
Post
by QQleQ » Mon Nov 20, 2006 10:09 pm
Hi there
All this script does is writing sentences or words to a textfile.. if its not in either deaud.txt or god.txt already.
Its working like a charm, however, i cant seem to get rid of some strange white lines (line breaks) in the text file. They keep comming back, even though i edit them out using vi.
Help apreciated.
Code: Select all
bind pub n !deaud add:deaud
set deauds [split [read [set file [open "deaud.txt"]]] \n][close $file]
unset file
set god [split [read [set file [open "god.txt"]]] \n][close $file]
unset file
proc add:deaud {n u h c a} {
global deauds
global god
if { [set b [split $a]] != "" } {
if {[lsearch -exact $deauds [set b [split $a]]] == -1} {
if {[lsearch -exact $god [set b [split $a]]] == -1} {
lappend deauds $b
putmsg $c "$b toegevoegd aan de deaudenlijst."
save:deaud
} {
putmsg $c "$b staat al op de godenlijst."
}
} {
putmsg $c "$b staat al op de deaudenlijst."
}
} {
set qot_fd [open "deaud.txt" r]
for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } {
gets $qot_fd qot_list($qot_cnt)
}
close $qot_fd
set qot_cnt [expr $qot_cnt - 2]
set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]])
putmsg $c "$qot_sel moet deaud. ([expr $qot_cur + 1] van [expr $qot_cnt + 1])"
}
}
proc save:deaud {} {
set a [open "deaud.txt" w]
foreach bn $::deauds {
puts $a $bn
}
close $a
}
rosc2112
Revered One
Posts: 1454 Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania
Post
by rosc2112 » Mon Nov 20, 2006 11:32 pm
Code: Select all
foreach bn $::deauds {
puts $a [join $bn \n]
}
Should do it..
I'd also put in a
Code: Select all
if {$bn != ""} {
puts $a [join $bn \n]
}
so its not saving blank lines..
QQleQ
Voice
Posts: 14 Joined: Mon Nov 20, 2006 10:05 pm
Post
by QQleQ » Tue Nov 21, 2006 12:27 am
Hmz, for some reason that aint working
the text file now looks like this:
Code: Select all
Zinloos Geweld
deadscripts
werkoverleg
maczut
loppie
Newlines
Het oude god-script
TiefusLineBreaks
Where the newly added lines are added from loppie (with this script) (the older lines where manually added with vi)
The script now looks like this:
Code: Select all
bind pub - !deaud add:deaud
set deauds [split [read [set file [open "deaud.txt"]]] \n][close $file]
unset file
set god [split [read [set file [open "god.txt"]]] \n][close $file]
unset file
proc add:deaud {n u h c a} {
global deauds
global god
if { [set b [split $a]] != "" } {
if {[lsearch -exact $deauds [set b [split $a]]] == -1} {
if {[lsearch -exact $god [set b [split $a]]] == -1} {
lappend deauds $b
putmsg $c "$b toegevoegd aan de deaudenlijst."
save:deaud
} {
putmsg $c "$b staat al op de godenlijst."
}
} {
putmsg $c "$b staat al op de deaudenlijst."
}
} {
set qot_fd [open "deaud.txt" r]
for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } {
gets $qot_fd qot_list($qot_cnt)
}
close $qot_fd
set qot_cnt [expr $qot_cnt - 2]
set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]])
putmsg $c "$qot_sel moet deaud. ([expr $qot_cur + 1] van [expr $qot_cnt + 1])"
}
}
proc save:deaud {} {
set a [open "deaud.txt" w]
foreach line [split $::deauds \n] {
if {$line != "" && $line != "\n"} {
puts $a [join $line \n]
}
}
close $a
}
What am i doing wrong?
rosc2112
Revered One
Posts: 1454 Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania
Post
by rosc2112 » Tue Nov 21, 2006 3:02 pm
You split the line twice, once again with the foreach..
De Kus
Revered One
Posts: 1361 Joined: Sun Dec 15, 2002 11:41 am
Location: Germany
Post
by De Kus » Thu Nov 23, 2006 3:41 pm
wouldnt just
Code: Select all
proc save:deaud {} {
set a [open "deaud.txt" w]
puts -nonewline $a [join $::deauds \n]
close $a
}
do the trick?
PS: I would move "[close $file]" to the next line and remove [] braces. close is not suposed to return anything but an empty string, but I still wouldn't add a probably empty string to something I want to parse as a consident list.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under
The MIT License
Love hurts, love strengthens...