[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  how to delay time before send command when a trigger activated

how to delay time before send command when a trigger activated

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Jlake   (4 posts)  [Biography] bio
Date Fri 29 Mar 2002 01:09 AM (UTC)
Message
because the job has busy time
I have to delay some time before send the command
how to do this?
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 29 Mar 2002 10:06 PM (UTC)
Message
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, ""


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 29 Mar 2002 10:16 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Jlake   (4 posts)  [Biography] bio
Date Reply #3 on Mon 01 Apr 2002 11:47 AM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 01 Apr 2002 10:12 PM (UTC)
Message
Good idea. Improved ways of sending delayed messages will be something I will look at.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Stoned00d   (14 posts)  [Biography] bio
Date Reply #5 on Wed 24 Apr 2002 08:20 PM (UTC)
Message
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...
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Wed 24 Apr 2002 11:42 PM (UTC)
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Tue 07 May 2002 08:51 AM (UTC)
Message
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"

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


22,058 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]