egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stuck with Remove Text from file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
kris
Voice


Joined: 12 Sep 2006
Posts: 14
Location: Perth, Australia

PostPosted: Mon Oct 02, 2006 8:36 am    Post subject: Stuck with Remove Text from file Reply with quote

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
View user's profile Send private message Visit poster's website
krimson
Halfop


Joined: 19 Apr 2006
Posts: 86

PostPosted: Mon Oct 02, 2006 9:28 am    Post subject: Reply with quote

- 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
View user's profile Send private message Send e-mail
kris
Voice


Joined: 12 Sep 2006
Posts: 14
Location: Perth, Australia

PostPosted: Mon Oct 02, 2006 11:47 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Mon Oct 02, 2006 1:11 pm    Post subject: Reply with quote

Your script makes no sense. You should at the very least know what your script is doing.
Back to top
View user's profile Send private message
krimson
Halfop


Joined: 19 Apr 2006
Posts: 86

PostPosted: Mon Oct 02, 2006 1:13 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
kris
Voice


Joined: 12 Sep 2006
Posts: 14
Location: Perth, Australia

PostPosted: Tue Oct 03, 2006 3:13 am    Post subject: Reply with quote

metroid wrote:
Your script makes no sense. You should at the very least know what your script is doing.


i do know Smile it reads the file, and ment to delete the text and move all the other text to where it is
Back to top
View user's profile Send private message Visit poster's website
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Tue Oct 03, 2006 11:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber