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

Posted by Andy.Liu on Mon 13 Mar 2017 06:02 AM — 9 posts, 33,204 views.

#0
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

Amended on Mon 13 Mar 2017 10:55 PM by Nick Gammon
Australia Forum Administrator #1
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.
#2
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.
Australia Forum Administrator #3
You put "OnRepeat" in the "Script" box in the alias. I mentioned that above. I don't know how else to explain that.
USA Global Moderator #4
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
#5
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.
USA Global Moderator #6
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.
Amended on Tue 14 Mar 2017 08:42 AM by Fiendish
Australia Forum Administrator #7
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 "#".
Amended on Tue 14 Mar 2017 09:46 AM by Nick Gammon
#8
Thank you for your comment.
It works after speedwalking disabled.