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 

File Reading (Code to learn file functions); error

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive
View previous topic :: View next topic  
Author Message
darkmare
Voice


Joined: 12 Apr 2004
Posts: 12
Location: Beaverton, OR

PostPosted: Mon Aug 08, 2005 6:37 pm    Post subject: File Reading (Code to learn file functions); error Reply with quote

To learn about playing with files, I put this code in the v2-alpha of my bot. (If you'd like to see examples of some of it's new code, go to http://3whack.org/forums and look all the way at the bottom under PIxelCat Dev Team).

When I try to read the file, it gets all the way through the code, but doesn't spit anything out. Via the telnet, I get this error: "[15:18] Tcl error [act:trigger]: can not find channel named "file14""

What shows in channel is this:
* AuntieChrist Pix file read test.egt (yeah, I'm silly, I made a file extention for EGgdrop Text)
* PixelCatv2 file14
* PixelCatv2 opened file named test.egt
* PixelCatv2 read file named test.egt
* PixelCatv2 closed file named test.egt

For my tutorial, I used this post here: http://forum.egghelp.org/viewtopic.php?t=6885
The append and create work just fine, the reading isn't.
Code:

proc act:trigger {nick mask hand chan keyword arg} {
if {[lindex $arg 0] == "Pix"} {
   global temp_file data counter temp_string file_name
   set temp_file ""
   set data ""
   set temp_string ""
   set file_name [lindex $arg 3]
   if {[lindex $arg 2] == "create"} {
      set temp_file [open $file_name "w+"]
      putserv "PRIVMSG $chan :\001ACTION created file named $file_name\001"
      close $temp_file
      putserv "PRIVMSG $chan :\001ACTION closed file named $file_name\001"
      return
   }
   if {[lindex $arg 2] == "read"} {
      set temp_file [open $file_name "r"]
      putserv "PRIVMSG $chan :\001ACTION $temp_file\001"
      putserv "PRIVMSG $chan :\001ACTION opened file named $file_name\001"
      putserv "PRIVMSG $chan :\001ACTION read file named $file_name\001"
      close $temp_file
      putserv "PRIVMSG $chan :\001ACTION closed file named $file_name\001"
      set data [read -nonewline $temp_file]
      putlog "Debug B"
      set temp_string [split $data "\n"]
      putserv "PRIVMSG $chan :\001ACTION is parsing data. . .\001"
      set counter 0
      while {$counter <= [llength $data]} {
         putserv "PRIVMSG #chan :\001ACTION sees [lindex $temp_string $counter] as line [$counter + 1] in $file_name.\001"
         incr counter
      }
      return
   }
   if {[lindex $arg 2] == "append"} {
   set temp_file [open $file_name "r"]
   putserv "PRIVMSG $chan :\001ACTION opened file named $file_name\001"
   set temp_string ""
      set counter 4
      while {$counter <= [llength $arg]} {
         lappend temp_string [lindex $arg $counter]
         incr counter
      }
      set [lindex $arg 3] [open $file_name "a"]
      puts $temp_file $temp_string
      putserv "PRIVMSG $chan :\001ACTION appended $temp_string to file named $file_name\001"
      close $temp_file
      putserv "PRIVMSG $chan :\001ACTION closed file named $file_name\001"
      return
   }

}
}


Any help would be appreciated,
Brendan
_________________

Brendan K Callahan Undernet: MaryFinn & PixelCat on #Mary'sPlace | http://3whack.org/brendan/ Theft by Deception DnB music (Released under the CreativeCommons License)


Last edited by darkmare on Mon Aug 08, 2005 6:56 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Aug 08, 2005 6:51 pm    Post subject: Reply with quote

You didn't read the first sticky topic in this forum, use [code] tags when showing snippets.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darkmare
Voice


Joined: 12 Apr 2004
Posts: 12
Location: Beaverton, OR

PostPosted: Mon Aug 08, 2005 6:57 pm    Post subject: Reply with quote

Well, I did, but it was over a year ago Smile I only come here when I've gone over stuff for hours, and no luck, hence the long time between visits. My apologies.
_________________

Brendan K Callahan Undernet: MaryFinn & PixelCat on #Mary'sPlace | http://3whack.org/brendan/ Theft by Deception DnB music (Released under the CreativeCommons License)
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Aug 08, 2005 7:01 pm    Post subject: Reply with quote

darkmare wrote:
Well, I did, but it was over a year ago Smile

Hehe, demond's post is less than a week old Razz

Anyway, the first thing I caught was this:
Code:
set data [read -nonewline $temp_file]

you already closed $temp_file, you can't read it.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darkmare
Voice


Joined: 12 Apr 2004
Posts: 12
Location: Beaverton, OR

PostPosted: Mon Aug 08, 2005 7:04 pm    Post subject: Reply with quote

I meant, I read all the FAQs and such; I didn't look at dates for any new ones, *that* part is my bad Embarassed
_________________

Brendan K Callahan Undernet: MaryFinn & PixelCat on #Mary'sPlace | http://3whack.org/brendan/ Theft by Deception DnB music (Released under the CreativeCommons License)
Back to top
View user's profile Send private message Visit poster's website
darkmare
Voice


Joined: 12 Apr 2004
Posts: 12
Location: Beaverton, OR

PostPosted: Mon Aug 08, 2005 8:09 pm    Post subject: Reply with quote

OK, we're getting somewhere now. The code that works is as follows: (Mostly so those that come after me see what the fix was)
Code:

proc act:trigger {nick mask hand chan keyword arg} {
if {[lindex $arg 0] == "Pix"} {
   global temp_file data counter temp_string file_name length
   set temp_file ""
   set data ""
   set temp_string ""
   set file_name [lindex $arg 3]
   if {[lindex $arg 2] == "create"} {
      set temp_file [open $file_name "w+"]
      putserv "PRIVMSG $chan :\001ACTION created file named $file_name\001"
      close $temp_file
      putserv "PRIVMSG $chan :\001ACTION closed file named $file_name\001"
      return
   }
   if {[lindex $arg 2] == "read"} {
      set temp_file [open $file_name "r"]
      putserv "PRIVMSG $chan :\001ACTION opened file named $file_name\001"
      putserv "PRIVMSG $chan :\001ACTION read file named $file_name\001"
      set data [read -nonewline $temp_file]
      set temp_string [split $data "\n"]
      set length [llength $temp_string]
      putserv "PRIVMSG $chan :\001ACTION is parsing data. . .\001"
      set counter 0
      while {$counter < $length} {
         putserv "PRIVMSG $chan :\001ACTION sees \"[lindex $temp_string $counter]\" as line $counter in $file_name.\001"
         incr counter
      }
      close $temp_file
      putserv "PRIVMSG $chan :\001ACTION closed file named $file_name\001"
      return
   }
   if {[lindex $arg 2] == "append"} {
   putserv "PRIVMSG $chan :\001ACTION opened file named $file_name\001"
   set temp_string ""
      set counter 4
      while {$counter <= [llength $arg]} {
         lappend temp_string [lindex $arg $counter]
         incr counter
      }
      set temp_file [open $file_name "a"]
      puts $temp_file $temp_string
      putserv "PRIVMSG $chan :\001ACTION appended \"$temp_string\" to file named $file_name\001"
      close $temp_file
      putserv "PRIVMSG $chan :\001ACTION closed file named $file_name\001"
      return
   }

}
}


Now, while not an error per se, I am getting some strange stuff:
Quote:

* AuntieChrist Pix file append test.egt I Like Blue.
* PixelCatv2 opened file named test.egt
* PixelCatv2 appended "I Like Blue. {}" to file named test.egt
* PixelCatv2 closed file named test.egt
* AuntieChrist Pix file read test.egt
* PixelCatv2 opened file named test.egt
* PixelCatv2 read file named test.egt
* PixelCatv2 is parsing data. . .
* PixelCatv2 sees "Now for something *really* different. {}" as line 0 in test.egt.
* PixelCatv2 sees "Something not so different. {}" as line 1 in test.egt.
* PixelCatv2 sees "I Like Blue. {}" as line 2 in test.egt.
* PixelCatv2 closed file named test.egt


Where are those braces and the space coming from? Is there a way to get rid of them?

And thanks for the help
_________________

Brendan K Callahan Undernet: MaryFinn & PixelCat on #Mary'sPlace | http://3whack.org/brendan/ Theft by Deception DnB music (Released under the CreativeCommons License)
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Aug 08, 2005 9:38 pm    Post subject: Reply with quote

Try [split $arg] instead of $arg.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darkmare
Voice


Joined: 12 Apr 2004
Posts: 12
Location: Beaverton, OR

PostPosted: Mon Aug 08, 2005 10:26 pm    Post subject: Reply with quote

OK, there's two places that could go, though I'm pretty sure you meant the one in the while statement. More importantly to me is *why* is that getting in there? I mean, where is that token coming from? Is this some default behaviour I could override?

OK, I found it. Easier solution is to change the <= to < Smile
_________________

Brendan K Callahan Undernet: MaryFinn & PixelCat on #Mary'sPlace | http://3whack.org/brendan/ Theft by Deception DnB music (Released under the CreativeCommons License)
Back to top
View user's profile Send private message Visit poster's website
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Aug 09, 2005 3:34 am    Post subject: Reply with quote

{} is the last (empty) string which you get when splitting data by \n and your file ends with \n
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive 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