Register forum user name Search FAQ

Gammon Forum

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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ How to understand example script function OnRepeat (name, line, wildcards)

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 page


Posted by Andy.Liu   (22 posts)  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

Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
Top

Posted by Andy.Liu   (22 posts)  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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
Top

Posted by Fiendish   USA  (2,558 posts)  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
Top

Posted by Andy.Liu   (22 posts)  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.
Top

Posted by Fiendish   USA  (2,558 posts)  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
Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
Top

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


31,515 views.

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

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.