| View previous topic :: View next topic |
| Author |
Message |
cannot_delete Voice
Joined: 24 Nov 2006 Posts: 31
|
Posted: Tue Feb 06, 2007 1:10 pm Post subject: milliseconds |
|
|
Hi,
I need help with the following problem. As I understand it, this code (being a part of the moxquizz.tcl) is responsible for calculating a duration and prettyprinting it. Now I want to add milliseconds to the equation, but I don't know how.
[code]## return a duration as a string
proc mx_duration {time} {
variable dur [duration [expr [unixtime] - $time]]
regsub -all "seconds" $dur [mc "seconds"] dur
regsub -all "second" $dur [mc "second"] dur
regsub -all "minutes" $dur [mc "minutes"] dur
regsub -all "minute" $dur [mc "minute"] dur
regsub -all "hours" $dur [mc "hours"] dur
regsub -all "hour" $dur [mc "hour"] dur
regsub -all "days" $dur [mc "days"] dur
regsub -all "day" $dur [mc "day"] dur
regsub -all "weeks" $dur [mc "weeks"] dur
regsub -all "week" $dur [mc "week"] dur
regsub -all "months" $dur [mc "months"] dur
regsub -all "month" $dur [mc "month"] dur
return $dur
}
[code]
Thanks for your help,
-typ-[/code] |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Feb 06, 2007 1:36 pm Post subject: |
|
|
The main problem is that "unixtime" does not keep track of fractions of a second. You could always use "clock clicks" if it is available on your platform; keep in mind however, that this will return a system-dependant time-measurement, often the smallest time-period your system may measure (cpu-clock or such). As of tcl8.3 there is an option "-milliseconds" that will guarantee measurements in milliseconds across platforms, which you might be able to utilize. Keep in mind that you might have to handle overflow situations in some cases, as integers in tcl are not large enough to hold the additional information compared to "unixtime". Also, keep in mind that the integer returned by "clock clicks -milliseconds" is a signed integer.
Now, keeping in mind of these issues, it should'nt be too hard to use clock-clicks in your current code. You'd obviously have to convert your millisecond time into "unixtime" time when using the "duration" command. A simple division should solve that, while a modulus would extract the millisecond offset. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
cannot_delete Voice
Joined: 24 Nov 2006 Posts: 31
|
Posted: Tue Feb 06, 2007 1:53 pm Post subject: |
|
|
thx for your help. =D
-typ- |
|
| Back to top |
|
 |
cannot_delete Voice
Joined: 24 Nov 2006 Posts: 31
|
Posted: Tue Feb 06, 2007 4:15 pm Post subject: |
|
|
Here's my result:
| Code: | ## return a duration as a string
proc mx_durationtyp {time} {
variable dur [duration [expr [clock clicks]] - $time]]
regsub -all "milliseconds" $dur [mc "milliseconds"] dur
regsub -all "millisecond" $dur [mc "millisecond"] dur
regsub -all "seconds" $dur [mc "seconds"] dur
regsub -all "second" $dur [mc "second"] dur
regsub -all "minutes" $dur [mc "minutes"] dur
regsub -all "minute" $dur [mc "minute"] dur
regsub -all "hours" $dur [mc "hours"] dur
regsub -all "hour" $dur [mc "hour"] dur
regsub -all "days" $dur [mc "days"] dur
regsub -all "day" $dur [mc "day"] dur
regsub -all "weeks" $dur [mc "weeks"] dur
regsub -all "week" $dur [mc "week"] dur
regsub -all "months" $dur [mc "months"] dur
regsub -all "month" $dur [mc "month"] dur
return $dur
} |
I changed the time variable like this (I added a "typ" into my changes. the line above is the original version):
| Code: | variable timeasked [unixtime]
variable timeaskedtyp [clock clicks] |
| Code: |
proc moxquiz_pubm {nick host handle channel text} {
global quizstate banner bannerspace
global timeasked theq aftergame
global timeaskedtyp theq aftergame |
| Code: | set duration [mx_duration $timeasked]
set durationtyp [mx_durationtyp $timeaskedtyp] |
| Code: | | mxirc_say $channel [mc "%s solved after %s and now has %s<%d>%s points (+%d) on rank %d." "[banner] [botcolor nick]$nick[botcolor txt]" $durationtyp [botcolor nick] $userarray(score) [botcolor txt] $theq(Score) [mx_get_rank_pos $nick]] |
Unfortunally I can only post these sniplets. the whole script would be too long.
I forgot to tell: I didn't get it working.
thx for your help,
-typ- |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Feb 06, 2007 4:21 pm Post subject: |
|
|
"duration" expects the time to be in seconds, hence you'll need to take apropriate actions to convert the millisecond-based time into second-based. See my previous post on suggestions on how to do this. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
cannot_delete Voice
Joined: 24 Nov 2006 Posts: 31
|
Posted: Wed Feb 07, 2007 3:30 pm Post subject: |
|
|
ok, thx.
I could use some help on how to do that..
thx for your help,
-typ- |
|
| Back to top |
|
 |
cannot_delete Voice
Joined: 24 Nov 2006 Posts: 31
|
Posted: Wed Feb 14, 2007 7:21 pm Post subject: |
|
|
| please... =/ |
|
| Back to top |
|
 |
|