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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  How to understand example script function OnRepeat (name, line, wildcards)
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

How to understand example script function OnRepeat (name, line, wildcards)

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


Posted by Andy.Liu   (22 posts)  [Biography] bio
Date Mon 13 Mar 2017 06:02 AM (UTC)

Amended on Mon 13 Mar 2017 10:55 PM (UTC) by Nick Gammon

Message
I get a problem with function OnRepeat in the exampleScript.lua.

I don't know how to setup my alias.

This is what I got from the code:
1. Create a new alias with name:^#(\d+)\s+(.+)$
2. Enable Regulare Expression
3. Send to "Script Engine"
4. But what content to be sent in the "Send" field?
How to match the function OnRepeat and call OnRepeat correctly?

Thanks.



-- --------------------------------------------
-- Subroutine to be called to repeat a command.
--
--  Call from the alias: ^#(\d+)\s+(.+)$
--  Regular Expression: checked
--
--  Example of use:  #10 give sword to Trispis
--  This would send "give sword to Trispis" 10 times
-- --------------------------------------------
function OnRepeat (name, line, wildcards)

local count = wildcards [1]

  if not tonumber (count) then
    Note ("Repeat count must be numeric, you entered ", count)
    return
  end

  local i
  for i = 1, count do
    Send (wildcards [2])
  end
      
end  -- of OnRepeat

[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 13 Mar 2017 10:59 PM (UTC)
Message
In that example the code you posted was supposed to go into your script file, and the word "OnRepeat" would go into the Script box in the alias.

An alternative is to put the code into the Send box with a couple of modifications, like this:


<aliases>
  <alias
   match="^#(\d+)\s+(.+)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

local count = "%1"

if not tonumber (count) then
  Note ("Repeat count must be numeric, you entered ", count)
  return
end

for i = 1, count do
  Send ("%2")
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 Andy.Liu   (22 posts)  [Biography] bio
Date Reply #2 on Tue 14 Mar 2017 02:16 AM (UTC)
Message
I don't catch the point of OnRepeat usage.

Let me explain what I understood and will to do like below.

1. I create an alias in alias edit dialog box.

2. Matched:^#(\d+)\s+(.+)$

3. Enabled Regular Expression

4. .... I don't know how to call the OnRepeat in the Lua script.
Should I call OnRepeat(?,?,?), what should be these 3 paramters?

I final purpose is to use it in command window like "zmud" style: #5 push table or #5 wow Jack.

Yes,I got the second solution you said by searching the forum.But I am interested in the OnRepeat function in the example script,and want to know how it works.
Can you explain it more for it?
Thanks.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 14 Mar 2017 06:50 AM (UTC)
Message
You put "OnRepeat" in the "Script" box in the alias. I mentioned that above. I don't know how else to explain that.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #4 on Tue 14 Mar 2017 07:44 AM (UTC)
Message
Quote:
I final purpose is to use it in command window like "zmud" style: #5 push table or #5 wow Jack.

Then you don't need to do it yourself. There already is a plugin for that.

http://www.mushclient.com/plugins/Repeat_Command.xml

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Andy.Liu   (22 posts)  [Biography] bio
Date Reply #5 on Tue 14 Mar 2017 08:10 AM (UTC)
Message
I'v imported the repead_command plugin.

When I typed #3 kick sky in the command window,it got error with "Action code of C, O, L, or k not follow a speedwalk count(1-99)".

Can this Alias be input in command window directly?

Thanks.
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #6 on Tue 14 Mar 2017 08:38 AM (UTC)

Amended on Tue 14 Mar 2017 08:42 AM (UTC) by Fiendish

Message
It sounds like you have another script interfering. The plugin doesn't use Speedwalk.

Undo whatever else you did trying to get this to work besides loading the plugin.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Tue 14 Mar 2017 09:45 AM (UTC)

Amended on Tue 14 Mar 2017 09:46 AM (UTC) by Nick Gammon

Message
Andy Liu said:

When I typed #3 kick sky in the command window,it got error with "Action code of C, O, L, or k not follow a speedwalk count(1-99)".


Go into world configuration -> Input -> Commands and uncheck "Speed Walking".

The default for the speed walk character is "#".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Andy.Liu   (22 posts)  [Biography] bio
Date Reply #8 on Wed 15 Mar 2017 02:37 AM (UTC)
Message
Thank you for your comment.
It works after speedwalking disabled.
[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.


1,894 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 FutureQuest]