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 

Puts not working o_O

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


Joined: 02 Nov 2009
Posts: 4
Location: Bat Yam, Israel

PostPosted: Tue Nov 03, 2009 6:52 am    Post subject: Puts not working o_O Reply with quote

I've used puts a fair amount of times, not once has it cause this.
I get no error at all; the file exists, all the variables it needs exist and contain the right contents; but the file just doesn't get written to.
Code:
proc spidey:settings:greet { nick host hand chan text } {
   
    global nogreetpath
   
    if { [lindex $text 0] == "off" } {
        set nicklist [split [read -nonewline [open "$nogreetpath\\nogreet.txt" r]] "\n"]
        if { [lsearch $nicklist $nick] == -1 } {
            puts [open "$nogreetpath\\nogreet.txt" a] $nick
        }
        putnotc $nick "You will no longer be greeted when you enter a channel with me in it."
        putnotc $nick "Type \002!setting greet on\002 to be greeted again."
    } elseif { [lindex $text 0] == "on" } {
        set foundnick 0
        set nicklist [split [read -nonewline [open "$nogreetpath\\nogreet.txt" r]] "\n"]
        while { [lsearch $nicklist $nick] != -1 } {
            set index [lsearch $nicklist $nick]
            set nicklist [lreplace $nicklist $index $index]
        }
        puts [open "$nogreetpath\\nogreet.txt" w] [join $nicklist "\n"]
        putnotc $nick "You will be greeted every time you enter a channel with me in it."
        putnotc $nick "Type \002!setting greet off\002 to stop being greeted."
    } else {
        putnotc $nick "Invalid setting. Must be \002on|off\002."
    }
}

I put around some putlogs (removed from here) to see that the vars are all correct. They are, and the putlogs execute meaning it's not a conditions problem. The messages also get echoed correctly. Wth is this happening? The "on" setting also works; puts work fine there.
Back to top
View user's profile Send private message Visit poster's website
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Tue Nov 03, 2009 7:42 am    Post subject: Reply with quote

combining different things seem fine in order to shorten code and make it a bit faster, but definately hard to read - even if you are looking for an error.

my guess:

the channel which is being opened up with open isnt being closed, maybe you also would like to put in putlogs after each line to see where it stops working, explode the following part into different lines:

Code:

puts [open "$nogreetpath\\nogreet.txt" a] $nick


in example:
Code:

set filename "$nogreetpath/nogreet.txt"
set file [open $filename a]
puts $file $nick
close $file


Im kind of wondering why you are using \\ since I always used / to separate different directories from each other, works even on windows based systems. and $file (in my case) already exists I guess since you are reading from it as well?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Nov 03, 2009 2:47 pm    Post subject: Reply with quote

Just to confirm raider2k's suspicions; since you don't close the file, the output will never be flushed to the file, as tcl buffers file operations by default.

Further, invoking this proc over and over will "leak" file handlers, up until the point (usually around 1023 file handlers) where you have exhausted the available resources, and your eggdrop will be unable to open any other files or network connections.

Tcl does not come with a garbage collector, so you'll have to take the effort of keeping track/cleaning up your resources such as file handles and sockets yourself. The only cleanup done is the anonymous namespace of the proc itself (local variables will be removed as the proc ends).
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
henasraf
Voice


Joined: 02 Nov 2009
Posts: 4
Location: Bat Yam, Israel

PostPosted: Fri Nov 13, 2009 9:06 pm    Post subject: Reply with quote

Yeah... still not working. Same goes for another script of mine, too. Should be simple, but noooooooooo....
Code:
proc henasraf:satiel:add { nick host hand chan text } {
    if { $text != "" } {
        set fopen [open $::satielfile a]
        puts $fopen $text
        close $fopen
        putmsg $chan "Added <$text> to Satiels database"
    }
}

Sends the message to the channel but doesn't actually do anything to the file. $::satielfile refers to the right file path/name. Not a problem with the variable, it works fine for reading from the file. Iunno what to do |:
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Nov 13, 2009 9:30 pm    Post subject: Reply with quote

Should work like that, assuming you havn't already opened $::satielfile for writing without closing it earlier.
_________________
NML_375, idling at #eggdrop@IrcNET
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