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:
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.
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.