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.

Help: Trying to cause a dealy when writing to a file

Old posts that have not been replied to for several years.
Locked
Z
Zero4Zero

Help: Trying to cause a dealy when writing to a file

Post by Zero4Zero »

OK, the topic does not describe what i am trying to do very well... I am new with Tcl, and have only written 2 scripts (including this one).

I am trying to buffer some text to be written to a file, so it only writes one line every 2 seconds. I cant seem to get it to wait untill the first utimer is done before it executes the next. So far, i just seem to stack a bunch of timers.

Code: Select all

proc log:chat {nick host hand chan text} {
  global sub_dir
  global chat_sets
  global sub_file
  set sub_str "<$nick> $text"
  set sub_pointer [open $logdir/$sub_file w]
  utimer 2 [puts $sub_pointer "$chat_sets"]
  puts $sub_pointer "$sub_str"
  close $sub_pointer
}
How would i cause the code to wait for the previous timer to expire before counting down?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You can check if the utimer exists in [utimers], if yes then create another utimer using the seconds in the first timer + 1 for example, so it will trigger after 1 second from the first timer.
Z
Zero4Zero

Post by Zero4Zero »

Sorry for not being very bright.. so i use the command utimers to list which timers are active... How do i add up the seconds remaining for all the timers, and even know how many to count? Would i use a foreach?

Maybe its too late at night for my brain to be working (-_-;)

*edit*

Baka me. I guess the question is, if i keep the timerid of the last timer, how do i check how long it has left?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Yes, use foreach to get each timer in [utimers]
each utimer would be in this form:
{seconds {command} timerID}
you can either get the timerID to check if the utimer's active (that's if you do set id [utimer...]) or you can see if the command exists for example using string match -nocase your-command [lindex $utimer 1] where [lindex $utimer 1] is the command in the utimer.

As for the second timer, when you see that the first timer exists, you can do utimer [lindex $utimer 0] [your command].

Hope that clears it up :)
Locked