Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Python ➜ Timestamp prompts?

Timestamp prompts?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Rakon   USA  (123 posts)  Bio
Date Wed 24 May 2006 02:49 PM (UTC)

Amended on Wed 24 May 2006 03:36 PM (UTC) by Rakon

Message
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.

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #1 on Wed 24 May 2006 03:26 PM (UTC)

Amended on Wed 24 May 2006 03:28 PM (UTC) by LupusFatalis

Message

	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!
Top

Posted by Rakon   USA  (123 posts)  Bio
Date Reply #2 on Wed 24 May 2006 03:38 PM (UTC)
Message
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??


Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #3 on Wed 24 May 2006 04:33 PM (UTC)
Message
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.
Top

Posted by Nexes   (65 posts)  Bio
Date Reply #4 on Thu 20 Jul 2006 04:27 AM (UTC)
Message
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
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,903 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.