This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Writing to a TXT

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

if you want max speed on casual events and make slow on more frequent events, you could use a var like "recentlysaved" and set it to 1 each time you save, use a utimer to wait for 10sec until next save. or you generally initialize a 1 sec delayed save on each event (which gives time for more events to be saved within that 1sec).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Ok i will save on every 10 seconds should i use this:?

Code: Select all

bind time - ?10* savelist 
bind join - * addtolist 
bind part - * remfromlist 
bind sign - * remfromlist 

if {![file exists online.txt]} { close [open online.txt w] } 
set nicklist [split [read [set oltxt [open online.txt]]] \n][close $oltxt] 

proc savelist args { 
 set file [open online.txt w] 
 foreach n $::nicklist { 
  if {$n != ""} { puts $file $n } 
 } 
 close $file 
} 

proc addtolist {nick uhost hand chan} { 
 global nicklist 
 set nick [string tolower $nick] 
 if {[lsearch -exact $nicklist $nick] == -1} { 
  lappend nicklist $nick 
 } 
} 

proc remfromlist {nick uhost hand chan rsn} { 
 global nicklist 
 set nick [string tolower $nick] 
 if {[set i [lsearch -exact $nicklist $nick]] != -1} { 
  set nicklist [lreplace $nicklist $i $i] 
 } 
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

No, that's for every 10 minutes. For saving every 10 seconds:

Code: Select all

bind join - * addtolist
bind part - * remfromlist
bind sign - * remfromlist

if {![file exists online.txt]} { close [open online.txt w] }
set nicklist [split [read [set oltxt [open online.txt]]] \n][close $oltxt]
set recentnicks 0

if {[utimerexists savelist]==""} {
 utimer 10 savelist
}

proc savelist {} {
 global recentnicks
 if {$recentnicks} {
  set file [open online.txt w]
  foreach n $::nicklist {
   if {$n != ""} { puts $file $n }
  }
  close $file
  set recentnicks 0
 }
 utimer 10 savelist
}

proc addtolist {nick uhost hand chan} {
 global nicklist recentnicks
 set nick [string tolower $nick]
 if {[lsearch -exact $nicklist $nick] == -1} {
  lappend nicklist $nick
  set recentnicks 1
 }
}

proc remfromlist {nick uhost hand chan rsn} {
 global nicklist recentnicks
 set nick [string tolower $nick]
 if {[set i [lsearch -exact $nicklist $nick]] != -1} {
  set nicklist [lreplace $nicklist $i $i]
  set recentnicks 1
 }
}
Note: alltools.tcl should be loaded for the utimerexists command to work.
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Ok i gonna test :)
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Thanks all, working perfect!
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Nope, he works a couple of minutes and after that he isnt working anymore..
Post Reply