Timers, and Escape Characters

Posted by Mike Kilian on Thu 11 Apr 2002 02:59 AM — 7 posts, 27,534 views.

#0
Two topics here. First is I have a tick timer set up, and it triggers a script which sends a groupsay 'tick in 10 seconds' 10 seconds (more or less) before the tick. My problem is, sometimes I'd like to know exactly how long it is until the tick. Is there a VB script I can write to be called by an alias (call it "ttime") that will World.Note the time left before the timer (named "clock")fires?

Second, I use ; a lot to stack commands, but I also routinely change certain mud aliases on the fly to do multiple tasks. (ex. alias aa assist fred;assist john;cast 'blind') I know I can go into Game=>Configure=>Commands to check or uncheck command stacking, but it'd be easier if I could escape the ; while typing out my alias, ie. alias aa assist fred/;assist john/;cast 'blind'. I haven't been able to find an escape for this in the MushClient documentation, nor by trial and error.

Thanks for any assistance,

Mike
Australia Forum Administrator #1
Quote:

Is there a VB script I can write to be called by an alias (call it "ttime") that will World.Note the time left before the timer (named "clock")fires?


Not directly. However, make the tick timer remember the current time, and when you want to know the time to go, subtract the current time (now) from the time the tick timer was set up. I seem to recall a post about this a while ago. Try searching for that.



Quote:

I know I can go into Game=>Configure=>Commands to check or uncheck command stacking, but it'd be easier if I could escape the ; while typing out my alias


Here are two possibilities for you ...

  1. Use double semicolons, like this:


    alias aa assist fred;;assist john;;cast 'blind'

  2. Make an alias to turn off stacking. It would do this:


    world.setoption "enable_command_stack", 0


    Make another to turn it back on ...


    world.setoption "enable_command_stack", 1


    Then call those aliases when required.
Amended on Thu 11 Apr 2002 03:55 AM by Nick Gammon
#2
Double ;;. Why the hell didn't I think of that? Works perfect, thanks.

As for getting the timer countdown, yes, to have it do some math would be relatively easy, but I don't know how to get the time elapsed on the clock timer. There was a post awhile back ( http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=410 -"Timer triggers (help needed)" from July 30, 2001 in the Jscript Forum) where Nick wrote a script to get the time remaining on variable spells on variable people, but with my lack of experience using VBscript, I can't figure out which line makes the timer remember the current time (then set a variable to that and subtract it from 72 should work).

Heck, I think I can do it except I don't know how to call the time elapsed on the timer. Plus there's got to be a better way of storing variables than as world variables, isn't there?

My formal effort:

Sub TimeUntilTick (thename, theoutput, theWildcards)
World.SetVariable "elapsed", cint(World.GetTimer("clock"))
World.SetVariable "timeleft", (72-World.GetVariable(elapsed))
World.Note " " & World.GetVariable("timeleft") & " seconds until tick"
End Sub

Of course, I get an error that "World.GetTimer" is not a valid argument. Also, Object doesn't support this property or method: 'World.GetTimers' when I add the "s".

And I'm not sure the timeleft variable will be set by doing the math that way, but I haven't been able to get that far yet.

Mike
Amended on Thu 11 Apr 2002 08:00 AM by Mike Kilian
#3
Ok, did some testing on the math portion. Everything but the cint(World.GetTimer("clock")) should be correct.


Sub TimeUntilTick (thename, theoutput, theWildcards)
World.SetVariable "elapsed", cint(World.GetTimer("clock"))
World.SetVariable "timeleft", 72-World.GetVariable("elapsed")
World.Note " " & World.GetVariable("timeleft") & " seconds until tick"
End Sub


Mike
Australia Forum Administrator #4
You need to use "now" now. ;)

Try something like this:


world.setvariable "start_time", Now


... and then when you need the time to go ...


timeleft = 10 + DateDiff("s", Now, world.getvariable ("start_time"))


"Now" is the current time. DateDiff calculates the difference in seconds. Subtract (add?) that from the number of seconds you are interested in (in this case, 10) and you should get your time left.
#5
Thanks Nick :)

Sub clocktick (strTriggerName, strTriggerLine, arrWildcards)
World.ResetTimer "clock"
world.setvariable "start_time", Now
End Sub

Sub TimeUntilTick (thename, theoutput, theWildcards)
timeleft = (72+DateDiff("s", Now, world.getvariable ("start_time")))
World.Note " " & timeleft & " seconds until tick"
End Sub

This works provided I reset my "clock" timer every tick. Unfortunately I don't have that luxury. Once I go a tick without reseting the timer, I get -20 seconds to tick, -180 seconds to tick, etc. Any way to reset the start_time variable without reseting the timer?

Mike
Australia Forum Administrator #6
When the "clock" timer fires just reset the time now. Wouldn't that work? Like this ...


sub myTimer (strTimerName)
  ' whatever you do in the timer ...
  world.setvariable "start_time", Now 
end sub