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.

Stuck with Remove Text from file

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
kris
Voice
Posts: 14
Joined: Tue Sep 12, 2006 10:46 am
Location: Perth, Australia
Contact:

Stuck with Remove Text from file

Post by kris »

Code: Select all

bind msg "-|-" divorce msg_divorce
proc msg_divorce { nick userhost handle text } {
set file "/home/kris/Love/eggdrop/marriage.role"
set delete 0
set lines 0
set deletnick $nick
set deletext $text
set lines [lreplace $lines $nick $text]
set fp [open $file "w"]
puts $fp [join $lines "\n"]
close $fp
close $file
putquick "NOTICE $nick :You and $text have been divorced"
putquick "PRIVMSG #PIRCS :$nick and $text have gotten a divorce"
}
the error is [22:34] Tcl error [msg_divorce]: bad index "test1": must be integer or end?-integer?
Last edited by kris on Mon Oct 02, 2006 11:46 am, edited 1 time in total.
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

- try reading the manual on lreplace.
- what do you use $deletenick and $deletext for?
- it's not such a good practice to set the file path each time you're calling the proc. this should be done somewhere outside, in a config only area

ps: please use

Code: Select all

 tags when posting any type of code
User avatar
kris
Voice
Posts: 14
Joined: Tue Sep 12, 2006 10:46 am
Location: Perth, Australia
Contact:

Post by kris »

ok, im reading the manual

-delenick and deletext are deleted.
-code brackets done.

Code:

Code: Select all

et mrryrole "/home/kris/Love/eggdrop/marriage.role"
bind msg "-|-" divorce msg_divorce
proc msg_divorce { nick userhost handle text } {
set file "/home/kris/Love/eggdrop/marriage.role"
set delete 0
set lines 0
set lines [lreplace $nick end end]
set fp [open $file "w"]
puts $fp [join $lines "\n"]
close $fp
set del [lreplace $text end end]
set combine [open $file "w"]
puts combine [join $del "\n"]
close $file
putquick "NOTICE $nick :You and $text have been divorced"
putquick "PRIVMSG #PIRCS :$nick and $text have gotten a divorce"
}
error: [02:09] Tcl error [msg_divorce]: can not find channel named "combine"
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Your script makes no sense. You should at the very least know what your script is doing.
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

one thing i notice is that you're not closing 'combine' at all.
this:

Code: Select all

set combine [open $file "w"]
puts combine [join $del "\n"]
close $file
should be this:

Code: Select all

set combine [open $file "w"]
puts combine [join $del "\n"]
close $combine
a full ".tcl $errorInfo" would be of great use.
User avatar
kris
Voice
Posts: 14
Joined: Tue Sep 12, 2006 10:46 am
Location: Perth, Australia
Contact:

Post by kris »

metroid wrote:Your script makes no sense. You should at the very least know what your script is doing.
i do know :) it reads the file, and ment to delete the text and move all the other text to where it is
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

what your script is meant to do and what it WOULD do are 2 very different things:

Code: Select all

set mrryrole "/home/kris/Love/eggdrop/marriage.role"
bind msg "-|-" divorce msg_divorce
proc msg_divorce { nick userhost handle text } {
set file "/home/kris/Love/eggdrop/marriage.role"
set delete 0
set lines 0
set lines [lreplace $nick end end]
set fp [open $file "w"]
puts $fp [join $lines "\n"]
close $fp
set del [lreplace $text end end]
set combine [open $file "w"]
puts combine [join $del "\n"]
close $file
putquick "NOTICE $nick :You and $text have been divorced"
putquick "PRIVMSG #PIRCS :$nick and $text have gotten a divorce"
} 
Let's start with telling you the very wrong parts.

1: You define your file twice, you seem to have just pasted it outside the proc but you don't actually use it.
2: You make useless variables that you don't even use in the end.
3:

Code: Select all

set lines [lreplace $nick end end]
What is this supposed to do?
Trust me when i say, it does not.

You use lreplace on a STRING, furthermore, what is there to replace in a 1 "word" variable, it will only contain your nick, no other words.

You open your file, and you put "$lines" in it, which probably has nothing in it. Then you make a variable called del, and you again use lreplace on a STRING, so like before, nothing exciting will happen except for the problem with special characters, then you open your file again and you again put something in it.

So like i said before, your piece of text encased in code tags makes no sense. It wouldn't do much of anything.
Post Reply