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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ VBscript
➜ Stop Watch?
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| MattMc
USA (54 posts) Bio
|
Date
| Wed 14 Jan 2004 01:55 AM (UTC) |
Message
| 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 14 Jan 2004 03:33 AM (UTC) |
Message
| 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). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| MattMc
USA (54 posts) Bio
|
Date
| Reply #2 on Wed 14 Jan 2004 08:15 PM (UTC) |
Message
| 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 | Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #3 on Thu 15 Jan 2004 10:01 AM (UTC) |
Message
| 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 :)
| Top |
|
Posted by
| MattMc
USA (54 posts) Bio
|
Date
| Reply #4 on Thu 15 Jan 2004 12:53 PM (UTC) |
Message
| 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 | Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #5 on Thu 15 Jan 2004 03:14 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #6 on Thu 15 Jan 2004 03:19 PM (UTC) |
Message
| Oh, silly me. If you want to avoid hacking up your script to include all those Dim's, you can first try doing:
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. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #7 on Thu 15 Jan 2004 08:00 PM (UTC) Amended on Thu 15 Jan 2004 08:01 PM (UTC) by Nick Gammon
|
Message
| |
Posted by
| MattMc
USA (54 posts) Bio
|
Date
| Reply #8 on Thu 15 Jan 2004 08:27 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Magnum
Canada (580 posts) Bio
|
Date
| Reply #9 on Mon 19 Jan 2004 03:44 PM (UTC) |
Message
| 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
|
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | 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.
35,497 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top