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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Nested function calls

Nested function calls

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


Posted by Winddancer   (26 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,928 posts)  [Biography] 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>



Template:pasting 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
[Go to top] top

Posted by Winddancer   (26 posts)  [Biography] bio
Date Reply #2 on Thu 03 Nov 2022 06:52 AM (UTC)
Message
Thanks. Must have overlooked that post of yours.
[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.


3,321 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]