| View previous topic :: View next topic |
| Author |
Message |
kris Voice

Joined: 12 Sep 2006 Posts: 14 Location: Perth, Australia
|
Posted: Mon Oct 02, 2006 8:36 am Post subject: Stuck with Remove Text from file |
|
|
| Code: |
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 |
|
| Back to top |
|
 |
krimson Halfop

Joined: 19 Apr 2006 Posts: 86
|
Posted: Mon Oct 02, 2006 9:28 am Post subject: |
|
|
- 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] tags when posting any type of code |
|
| Back to top |
|
 |
kris Voice

Joined: 12 Sep 2006 Posts: 14 Location: Perth, Australia
|
Posted: Mon Oct 02, 2006 11:47 am Post subject: |
|
|
ok, im reading the manual
-delenick and deletext are deleted.
-code brackets done.
Code:
| Code: |
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" |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Mon Oct 02, 2006 1:11 pm Post subject: |
|
|
| Your script makes no sense. You should at the very least know what your script is doing. |
|
| Back to top |
|
 |
krimson Halfop

Joined: 19 Apr 2006 Posts: 86
|
Posted: Mon Oct 02, 2006 1:13 pm Post subject: |
|
|
one thing i notice is that you're not closing 'combine' at all.
this: | Code: | set combine [open $file "w"]
puts combine [join $del "\n"]
close $file |
should be this: | Code: | set combine [open $file "w"]
puts combine [join $del "\n"]
close $combine |
a full ".tcl $errorInfo" would be of great use. |
|
| Back to top |
|
 |
kris Voice

Joined: 12 Sep 2006 Posts: 14 Location: Perth, Australia
|
Posted: Tue Oct 03, 2006 3:13 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Tue Oct 03, 2006 11:40 am Post subject: |
|
|
what your script is meant to do and what it WOULD do are 2 very different things:
| Code: |
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: | | 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. |
|
| Back to top |
|
 |
|