# repeat alias

Share your scripts and packages with other Mudlet users.
User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

# repeat alias

Post by Vadi »

Import xml, and you can do #number thing.

For example, #5 hi will send hi five times.
Attachments
#-repeat-alias.xml
(411 Bytes) Downloaded 1845 times

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: # repeat alias

Post by ulysses »

This is very nice, but what happens if you want to repeat an alias defined in MUDlet. In this case it doesn't work as it sends the alias string to the mud.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: # repeat alias

Post by Vadi »

Replace 'send(matches[3])' with 'expandAlias(matches[3])'

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: # repeat alias

Post by ulysses »

Parfait! Excellent! Thanks!
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: # repeat alias

Post by ulysses »

Vadi wrote:
Sat Feb 10, 2018 1:18 pm
Replace 'send(matches[3])' with 'expandAlias(matches[3])'
Actually that only works with single line aliases. For multi-line aliases it does not work! For example I have a alias

Code: Select all

pp
which looks like this:

Code: Select all

send("open pouch")
send("put "..matches[2].." in pouch")
send("close pouch")
If I do #10 pp alabaster, it just executes it once. Why?
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: # repeat alias

Post by Vadi »

No idea. Check the errors view, might give you a clue.

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: # repeat alias

Post by ulysses »

Vadi wrote:
Mon Feb 12, 2018 11:51 am
No idea. Check the errors view, might give you a clue.
There is an error, it says;

Code: Select all

LUA: ERROR running script # repeat alias (Alias23) ERROR:expandAlias: wrong argument type
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: # repeat alias

Post by ulysses »

Anyone got any idea about how to debug this. I'm generally new to Lua/Mudlet.

Thanks!
U
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: # repeat alias

Post by Jor'Mox »

Well, that error suggest that you are passing something other than a string to the expandAlias function, suggesting that your match is a nil value, in which case I wouldn't expect this to do anything anyway, since there is no command for it to be repeating. But, you could always use this: expandAlias(matches[3] or "")
To really see what is going on though, it would be helpful if you posted your exact regex pattern and code, so we could see any changes you had made that might be innocuous looking but problematic.

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: # repeat alias

Post by ulysses »

Jor'Mox wrote:
Sat Feb 24, 2018 12:16 am
Well, that error suggest that you are passing something other than a string to the expandAlias function, suggesting that your match is a nil value, in which case I wouldn't expect this to do anything anyway, since there is no command for it to be repeating. But, you could always use this: expandAlias(matches[3] or "")
To really see what is going on though, it would be helpful if you posted your exact regex pattern and code, so we could see any changes you had made that might be innocuous looking but problematic.
Hi Jor'Mox. Appreciate the response. The regex is untouched and looks like this;

Code: Select all

^#(\d+) (.*)$
The body looks like this:

Code: Select all

for i = 1, tonumber(matches[2]) do
	expandAlias(matches[3])
end
I just replaced send with expandAlias. I'm trying on my 'put pouch' alias which looks like this;

Code: Select all

^pp (.*)$
with body:

Code: Select all

send("open pouch")
send("put "..matches[2].." in pouch")
send("close pouch")
If I execute this command;

Code: Select all

#2 pp alabaster
It runs the first one, with the error above for the second (which is in the debug window):

Code: Select all

LUA OK script Put Item In Pouch (Alias3) ran without errors
LUA: ERROR running script # repeat alias (Alias28) ERROR:expandAlias: wrong argument type
So the first time around the iteration it did expandAlias fine but the second time around it appears matches[3] got changed. Perhaps it's because the pp alias also uses the matches variable? Should the repeat alias save off matches before doing expandAlias?

Thanks!
U
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Post Reply