how to delay time before send command when a trigger activated

Posted by Jlake on Fri 29 Mar 2002 01:09 AM — 8 posts, 32,834 views.

#0
because the job has busy time
I have to delay some time before send the command
how to do this?
Australia Forum Administrator #1
You can do two things...

  1. Set the trigger to "send to" : "World (speedwalk delay)".

    Then under Input -> Commands, set the speedwalk delay to (say) 1000 - which is one second. Then the trigger output will be sent with a one-second delay between each line.
  2. Alternatively, have the trigger call a script, and the script can use world.addtimer to add a timer. The timer can then send whatever you want to send after however many seconds you choose.

    eg.

    World.addtimer "my_timer", 0, 0, 1, "go north", 5, ""
Australia Forum Administrator #2
If you need to do this a lot you can make a script function that does that for you, and then call it from the trigger, to make it easier.

Also, if you are planning to do a lot of these you should give the timers all different names, as you can only have one timer of one name.

Look for posts by Krenath, he did something like that.
#3
thanks a lot.
but I think this soft should have more simple way to do this.
If it has not, I wish it will be added in next version.
Australia Forum Administrator #4
Good idea. Improved ways of sending delayed messages will be something I will look at.
#5
alternately, you could write a wait function

Function wait(N)
Dim StartTime, EndTime
StartTime = Timer
EndTime=Timer
While (EndTime-StartTime)<N
EndTime = Timer
Wend
End Function

where N is the number of seconds you would like to delay.

The downside to this is that you can't queue up any commands within the N seconds...
Australia Forum Administrator #6
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
Australia Forum Administrator #7
In version 3.19 onwards you can do that without any extra scripting. It now supports "world.doafter" which works the way it was described above.

eg.

world.doafter 10, "eat food"