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 for those learning Tcl or writing their own scripts.
intel
Halfop
Posts: 57 Joined: Tue Feb 26, 2008 11:51 pm
Post
by intel » Sat Jan 10, 2009 6:58 pm
Is there a way when my bot announces the time instead of hours it will display hrs (same for minutes and seconds)?
set time1 [unixtime]
incr time1 -$timestamp
set ago [duration $time1]
speechles
Revered One
Posts: 1398 Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)
Post
by speechles » Sat Jan 10, 2009 7:05 pm
Code: Select all
set ago [string map {"year" "yr" "week" "wk" "day" "dy" "hour" "hr" "minute" "min" "second" "sec"} [duration $time1]]
intel
Halfop
Posts: 57 Joined: Tue Feb 26, 2008 11:51 pm
Post
by intel » Sat Jan 10, 2009 7:24 pm
Thanx, but will that do hrs or just hr. Like 5 hrs ago or 5 hr ago?
speechles
Revered One
Posts: 1398 Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)
Post
by speechles » Sat Jan 10, 2009 7:40 pm
intel wrote: Thanx, but will that do hrs or just hr. Like 5 hrs ago or 5 hr ago?
It will change any occurence of "hour" to "hr" which is part of both words, hour and hours. So "hours" will be changed to "hrs", yes. The same goes for the rest of the abbreviations.
intel
Halfop
Posts: 57 Joined: Tue Feb 26, 2008 11:51 pm
Post
by intel » Sat Jan 10, 2009 8:03 pm
awesome... thanx
intel
Halfop
Posts: 57 Joined: Tue Feb 26, 2008 11:51 pm
Post
by intel » Mon Jan 12, 2009 8:02 am
oh would you know how to get rid of the space? It says 1 hr 15 min ago would like 1hr 15min ago
Thanks.
arfer
Master
Posts: 436 Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK
Post
by arfer » Mon Jan 12, 2009 8:14 am
You must include the space character in the mapped items to be replaced as follows :-
Code: Select all
set ago [string map {" year" "yr" " week" "wk" " day" "dy" " hour" "hr" " minute" "min" " second" "sec"} [duration $time1]]
For example :-
[12:19] <@arfer> % return [string map {" year" "yr" " week" "wk" " day" "dy" " hour" "hr" " minute" "min" " second" "sec"} [duration [unixtime]]]
[12:19] <@Baal> 39yrs 3wks 12hrs 19mins 6secs
intel
Halfop
Posts: 57 Joined: Tue Feb 26, 2008 11:51 pm
Post
by intel » Mon Jan 12, 2009 9:36 am
Great. It works. Thanx appreciate the all the help.
Just curious if I wanted say 12h 15m 10s would that just be
" hour" "" " minutes" "" or will just put either nothing or a s at the end (like 12 or 12s instead of 12hr or 12hrs)?
intel
Halfop
Posts: 57 Joined: Tue Feb 26, 2008 11:51 pm
Post
by intel » Mon Jan 12, 2009 6:01 pm
lol been tryin... used /m /s [m] [s] not working... so obviously doing something wrong.
incith
Master
Posts: 275 Joined: Sat Apr 23, 2005 2:16 am
Location: Canada
Post
by incith » Mon Jan 12, 2009 8:00 pm
You are mapping "{from} {to}", so if you want to replace hour with h, ...
{hour} {h} {minute} {m} etc.. you might need to do extra ones for the s, or try with {hour*} but that might end up replacing the whole string <_<. maybe hour? to check for the 1 additional char.
speechles
Revered One
Posts: 1398 Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)
Post
by speechles » Mon Jan 12, 2009 8:08 pm
Code: Select all
set ago [string map {" years" "y" " weeks" "w" " days" "d" " hours" "h" " minutes" "m" " seconds" "s" " year" "y" " week" "w" " day" "d" " hour" "h" " minute" "m" " second" "s"} [duration $time1]]
Make a big long string map in that case. Incith was correct, test these things on your own, so you learn intuitively and interactively.
intel
Halfop
Posts: 57 Joined: Tue Feb 26, 2008 11:51 pm
Post
by intel » Mon Jan 12, 2009 9:31 pm
Thanx. I did try that really long way but I didnt have it in that order so it did not work. It was still doing ms (for minutes) and ss (for seconds)
Thanx. Appreciate the help.