Stop Watch?

Posted by MattMc on Wed 14 Jan 2004 01:55 AM — 10 posts, 45,323 views.

USA #0
I'm trying to create a script that will gauge the amount of lag passing through a mud on command. I can make the trigger, but Ican't find any references to a stop watch in the forum or site.

Basically, when the client sees "String A", it starts the timer, echos something unique, and when it sees the return of that string it stops the timer and echos the time it took.

Any thoughts?


KidKreative
Australia Forum Administrator #1
I think someone did that ages ago. He called it a "lag timer" or something like that.

Your general idea is right. You can remember the time the message is sent (using Now I think) and then get the time it is echoed, and use DateDiff to find the difference (or TimeDiff).
USA #2
Hmm. I got the most part of it down.


sub StartLag (sName, sLine, strwildcards)
world.EchoInput = 0
world.send "emot gets a stop watch from his bra and presses it to begin counting."
World.SetVariable "lagcheck", time
world.EchoInput = 1
end sub

sub LagCheck (sname, sLine, strwildcards)
world.EchoInput = 0
durationA = datediff("s",getvariable("lagcheck"),time)
world.send "emot turns off the stop watch and announces, 'Trivia is lagging at " & durationA & " seconds!'"
world.EchoInput = 1
end sub


The problem is, it is either 0 seconds or 1 second... How would I convert this to miliseconds, where something can be actually determined :D
Russia #3
The function you need is Timer. You can have a global script var to hold the time when the command is sent and then get the time difference by simple subtraction, like this (note that if you send the command before midnight and get the reply after, you'll get a large negative value):


dim commandSent

sub StartLag (sName, sLine, strwildcards)
 world.EchoInput = 0
 world.send "emot gets a stop watch from his bra and presses it to begin counting."
 commandSent = Timer
 world.EchoInput = 1
end sub

sub LagCheck (sname, sLine, strwildcards)
 dim replyReceived, durationA
 replyReceived = Timer
 world.EchoInput = 0
 durationA = replyReceived - commandSent
 world.send "emot turns off the stop watch and announces, 'Trivia is lagging at " & durationA & " seconds!'"
 world.EchoInput = 1
end sub


Note that I used Dim's in there, since I have a strong distaste for using vbScript without option explicit, but that's a personal peeve you can safely ignore :)



USA #4
2 things:

1) Is this milliseconds or just a number?

2) Here is a log of the lag checks I did:

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31561.56 seconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31573.92 seconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31689.67 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31701.42 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31703.03 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31704.48 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31717.87 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31721.12 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31722.58 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31737.98 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31780.89 milliseconds!'

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31781.94 milliseconds!'

{Long Pause}

> Trivia turns off the stop watch and announces, 'Trivia is lagging at 31940.65 milliseconds!'


The numbers are completly consecutive... That can't be right...
Thoughts?

This appears to be a huge step closer then what I was doing, thanks!


Matt
Russia #5
Hmmmmm... The only explanation for this that I can come up with right now is that sub LagCheck is doing something like this:


durationA = replyReceived - 0


The only explanation for the latter, that I can come up with right now, is that my personal peeve about using vbScript only with option explicit isn't a mania but is in fact something practical. :P It might be that variable commandSent never gets out of local sub scope and is destroyed along with sub StartLag, when the latter finishes executing. In that case above situation could theoretically happen. Try setting option explicit in your script and dim'ing the variables to see what happens.
Russia #6
Oh, silly me. If you want to avoid hacking up your script to include all those Dim's, you can first try doing:


commandSent = Timer


in script's main body (outside subs or functions). Though I don't know much about how vbScript works without option explicit (probably pretty badly), I guess that it should do what Python and others do in such cases: create a variable in global scope.
Australia Forum Administrator #7
Instead of:


world.EchoInput = 0
world.send "blah"
world.EchoInput = 1


Try:


world. SendNoEcho "blah"



See:


http://www.gammon.com.au/scripts/doc.php?function=SendNoEcho
Amended on Thu 15 Jan 2004 08:01 PM by Nick Gammon
USA #8
Doh! I figured it out. You had it right, I just thought you did something incorrect so I fixed it.

dim commandSent you had as outside the sub.


I moved it inside. Therefore when the sub ended, so did commandSent. Oops :o. I should follow ya'll more verbatim. Thanks guys! It works awsome now. And thanks Nick for the fix.
Canada #9
Nick,

I assume SendNoEcho text is not logged either? Could you add a brief statement to that effect in that help link you provided?

Although I often send without echoing, I prefer to still log my sent text, so I still use the long method of
World.EchoInput = 0; World.LogSend "blah"; World.EchoInput = 1