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
➜ Tips and tricks
➜ 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 page
Posted by
| Jlake
(4 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Fri 29 Mar 2002 10:06 PM (UTC) |
Message
| You can do two things...
- 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.
- 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) 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 | Top |
|
Posted by
| Jlake
(4 posts) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) 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 | Top |
|
Posted by
| Stoned00d
(14 posts) 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... | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) 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 | 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.
25,975 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top