Gammon Forum
Entire forum
MUSHclient
General
Why It can't run in the order
Why It can't run in the order
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Tianxz
(30 posts) bio
|
Date
| Sat 09 Jul 2011 02:33 PM (UTC) |
Message
| function a()
DoAfter(1,"e")
end
function b()
DoAfter(0.1,"hp")
a()
DoAfter(0.1,"l")
end
The result is
hp then l then e
But I just want to it can run in the order
first:hp
after 1s then: e
then:l
Of course, If I change the DoAfter(0.1,"l") to DoAfter(2,"l"), the result is same I want. If I don't know how long it need to run for function a, how can I correct it? Thank you.
| top |
|
Posted by
| Tianxz
(30 posts) bio
|
Date
| Reply #1 on Sat 09 Jul 2011 02:36 PM (UTC) |
Message
| If some Doafter is nested in function a, it will be more complex. I think the important thing is how can let the code run in the order. | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #2 on Sat 09 Jul 2011 08:01 PM (UTC) |
Message
| DoAfter() sets a timer with the delay you specify, and immediately continues with the script. That means that in this script, "hi" is shown first:
DoAfter(0.1, "lol")
DoAfter(0.2, "rofl")
print("hi")
And then as time passes, MUSHclient runs the timers as they're fired, so "lol" would come after 0.1 seconds, and 0.1 seconds after that (i.e. 0.2 seconds from being created) "rofl" would show up.
I'd suggest doing this:
function a(delay)
DoAfter(delay, "e")
end
function b()
DoAfter(0.1, "hp")
a(1.1)
DoAter(1.2, "l")
end
You could also try using the "wait.lua" module, which uses coroutines to give you a pause mechanism closer to what you expect.
require "wait"
function a()
Send("e")
end
wait.make(function()
wait.time(0.1)
Send("hp")
wait.time(1)
a()
wait.time(0.1)
Send("l")
end)
|
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #3 on Sat 09 Jul 2011 09:47 PM (UTC) |
Message
| |
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.
14,761 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.