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 

Delete a line

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


Joined: 18 May 2014
Posts: 22

PostPosted: Sat Apr 13, 2019 4:25 am    Post subject: Delete a line Reply with quote

Code:
proc msg:calculate {nick host hand arg} {
  global botnick opchan
  set fname "remember.txt"
  set fp [open $fname "r"]
  set data [read -nonewline $fp]
  close $fp
  set lines [split $data "\n"]
  set linetodelete 0
  set lines [lreplace $lines $linetodelete $linetodelete]
  set fp [open $fp "w"]
  puts $fp [join $lines "\n"]
  close $fp
  putserv "PRIVMSG Fujin :Done."
}


I got this from this site but it won't work for me, could someone help me.
To remove a line from a txt file.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2839

PostPosted: Sat Apr 13, 2019 10:08 am    Post subject: Reply with quote

Hello,
Assuming you'd like to remove the top-line of the file named "remember.txt", the main problem is at line 10, where you open the file for write-access, but mistakenly use $fp instead of $fname for filename:
Code:
set fp [open $fp "w"]
should be changed into
Code:
set fp [open $fname "w"]


On a side-note, there's no point in mapping global varialbes botnick or opchan into this proc, as it never uses either of those variables.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
l.kleijn
Voice


Joined: 18 May 2014
Posts: 22

PostPosted: Sat Apr 13, 2019 11:29 am    Post subject: Reply with quote

Code:
proc msg:calculate {nick host hand arg} {
  global botnick opchan
  set fname "remember.txt"
  set fp [open $fname "r"]
  set data [read -nonewline $fp]
  close $fp
  set lines [split $data "\n"]
  set linetodelete [expr {[llength $lines] -1}]
  set fp [open $fname "w"]
  puts $fp [join $lines "\n"]
  close $fp
  putserv "PRIVMSG Fujin :Done."
}


It doesn't work i don't know anymore.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2839

PostPosted: Sat Apr 13, 2019 11:42 am    Post subject: Reply with quote

Well, it seems that you've done additional modifications since the original post; now you've removed the "lreplace" command, which is actually used to remove an element (line from the file) from the list (of lines), before writing it back to the file.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
l.kleijn
Voice


Joined: 18 May 2014
Posts: 22

PostPosted: Sat Apr 13, 2019 12:38 pm    Post subject: Reply with quote

But even with the quote of the original post, change the file you sayd, it don't work
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1008

PostPosted: Sat Apr 13, 2019 3:07 pm    Post subject: Reply with quote

l.kleijn wrote:
... it don't work


You need to give a better, more complete description of what is happening.

People here on the forum are not there with you. Can't see whatever you are seeing.

Put yourself in our shoes.
What does "it don't work" mean?

Did the bot crash?
Did you see errors in the partyline?

Is the bind that calls this procedure loaded?
Is its hit counter incrementing?

Any and every detail that you can see, please share it here.
_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Back to top
View user's profile Send private message
l.kleijn
Voice


Joined: 18 May 2014
Posts: 22

PostPosted: Sun Apr 14, 2019 2:28 am    Post subject: Reply with quote

I know what the problem was. i forgot the msg to bot. but it's working
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