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.
Entire forum
➜ MUSHclient
➜ General
➜ Nested function calls
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Winddancer
(26 posts) Bio
|
Date
| Wed 02 Nov 2022 09:59 PM (UTC) Amended on Wed 02 Nov 2022 10:22 PM (UTC) by Winddancer
|
Message
| In my mud, there is a delay when you read a page in a book before you can continue. Naturally I wanted to circumvent this with an alias and 2 functions.
What I want to do:
Step 1 Open the book
Step 2.1 read a page
Step 2.2 wait 5 seconds
Step 2.3 turn the page
Step 3 repeat Step 2 as often as I indicated in the alias call.
What I did:
I created the following script functions:
function readPage()
Send ("read book")
DoAfterSpecial (5, "turn page", sendto.world)
end --readPage
function readBook(x)
local i=1
while i <= x
do
readPage()
i=i+1
end -- do
end --readBook
<alias
match="readBook *"
enabled="y"
group="books"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>Send("open book")
readBook(%1)
</send>
What happens when I call the alias with "readBook 4":
I open the book
I send 4 times read book to the world
The first pages gets read.
I get 3 messages from the mud that I am reading the book. (because the delay is not yet over)
I get a message that I am finished reading the page
I send 4 times turn page to the world.
I turn a page 4 times
Where is my error? What did I do wrong?
When I call the readPage() function on its own, it works as intended:
I read the page.
After 4 seconds I get the message that I am finished reading the page.
I send turn page to the world.
The page gets turned. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 03 Nov 2022 12:08 AM (UTC) |
Message
| Check out my page about building pauses into scripts: http://www.gammon.com.au/forum/?id=4956
In your case your alias could look like this:
<aliases>
<alias
match="readBook *"
enabled="y"
send_to="12"
sequence="100"
>
<send>
if not tonumber ("%1") then
print "Number of pages not numeric"
return
end -- if
require "wait"
wait.make (function ()
Send("open book")
-- read each page
for i = 1, %1 do
Send ("read book")
wait.time (5)
Send ("turn page")
end -- for
print "Book reading done"
end)
</send>
</alias>
</aliases>
|
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Winddancer
(26 posts) Bio
|
Date
| Reply #2 on Thu 03 Nov 2022 06:52 AM (UTC) |
Message
| Thanks. Must have overlooked that post of yours. | 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.
5,667 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top