Timestamp prompts?

Posted by Rakon on Wed 24 May 2006 02:49 PM — 5 posts, 25,721 views.

USA #0
Greetings. In light of recent discussions, and with a search around the forums, I've decieded to try and add a TimeStamp to my prompt lines within logs. Now, while I have the regular H:M:S stamp, I've tried to add to that, a millisecond timer for latency, to print how long since the prompt last went off. Currently, the last part, is not working.

Here is what I am Trying to do:

4246h, 3771m, 18040e cexdb- <-Prompt
(10:39:40<Time, H:M:S 39.230 <Time since last prompt)
4246h, 3771m, 18040e cexdb-
(10:39:42 3.21)
But here's what is doing:

4246h, 3771m, 18040e cexdb-
(10:39:43 0.00)
Here I waited. About 2 minutes
4246h, 3771m, 18040e cexdb-
(10:43:24 0.00)

And finally, the code:

def Time(*args):
	time_now = time.strftime("(%H:%M:%S  ", time.localtime())
	log = world.GetVariable("log")
	previousTime = world.GetInfo(232)
	
	if log == "1":
		diff = world.GetInfo(232) - previousTime
		world.WriteLog(time_now + fpformat.fix(diff,2) + str(")"))
	previousTime = world.GetInfo(232)


Anyone have an idea as to why its not working properly?
Thanks.
Amended on Wed 24 May 2006 03:36 PM by Rakon
#1

	previousTime = world.GetInfo(232)
	
	if log == "1":
		diff = world.GetInfo(232) - previousTime


... it looks like your problem is that you are subtracting identical values, and getting 0, as you should. I'm not sure how subtracting times in python works, though you might have to convert everything to seconds, subtract, then convert back. Anyway good luck!
Amended on Wed 24 May 2006 03:28 PM by LupusFatalis
USA #2
hmm..Now that you mention it, yeah. That is a problem.
However, I can't seem to get a TRY:,EXECPT statement to work ither. Any ideas on how to set,'previousTime' AT the end of the function? And still have it remeber it when the function is called again??

#3
Hmm... well you could do a ...

world.SetVariable('LastPromptTime', str(PreviousTime))

and then later when its needed

world.GetVariable('LastPromptTime')

Now, the problem here is I don't know what your storing the "time" as... so whatever you are using to subtract the two, you'll have to convert the string back to that data type.
#4
I should have seen this thread sooner. The idea that it was left to using MUSHcilent variables is pretty sad really.

Ok, it's very simple, Python thinks that a variable is local to a function if you try to assign to it in that same function. To assing to the variable in the global namespace, you must declare the variable global. You can do that easily by doing something like global previousTime in the beginning of the function.

You can also have multiple variables on the same line seperated by commas, such as global x, y, z