Quote:
The downside to this is that you can't queue up any commands within the N seconds..
The problem with the function you gave is it basically "hangs" the client until the time elapses. While it is running you can't:
- Type in any commands
- Use the menus
- Receive data from the MUD
- Do anything much
You are better off using timers. The script function below illustrates doing this in VBscript. It takes two arguments, time to wait, and what to do when the time is up.
You can call it from the command line, or another script. To call it from the command line you would do this:
/DoAfter 5, "west"
/DoAfter 8, "eat bread"
The examples above would wait 5 seconds and go west, and wait 8 seconds and "eat bread" (both times from now).
To use it from another script you would just say:
DoAfter 22, "kick dragon"
The code uses the random-number generator to get a random name, and then loops to make sure that name isn't already in use.
const eEnabled = 1 ' is timer enabled?
const eOneShot = 4 ' if set, timer only fires once
const eReplace = 1024 ' replace existing timer of same name
Randomize timer
Sub DoAfter (iSecs, sCommand)
Dim iFlags, iHours, iMinutes, iSeconds, sName
'
' check time looks reasonable
'
If iSecs <= 0 then
World.Note "DoAfter called with zero or negative seconds"
Exit Sub
End If
If iSecs > 10000 then
World.Note "DoAfter called with more than 10000 seconds"
Exit Sub
End If
'
' work out a random name, loop until unique one found
'
Do
sName = "Timer_" & Int (32767 * Rnd (1) + 1)
Loop Until IsEmpty (World.GetTimerInfo (sName, 1))
'
' set flags
'
iFlags = eEnabled + eOneShot + eReplace
'
' convert supplied seconds to hours/minutes/seconds
'
iHours = Cint (iSecs / 3600)
iSecs = iSecs - (iHours * 3600)
iMinutes = Cint (iSecs / 60)
iSecs = iSecs - (iMinutes * 60)
'
' add the timer
'
World.AddTimer sName, iHours, iMinutes, iSecs, sCommand, iFlags, ""
End Sub
|