help with using a var or alias within a typed command

Posted by Guest1 on Thu 28 Aug 2003 05:07 AM — 8 posts, 31,878 views.

USA #0
Don't know if this can be done or how, but here's a little problem I have.

I am currently using a container held in my inventory that has a fairly long name to type in. What I'd like to do is to be able to type in an alias of sorts to substitute for the container name, but there are so many different things I may want to do with it that I don't really want to make masses of aliases for all the possible things I may use it for..

eg:
instead of typing in and sending to the mud

"put knife bag-of-goodies" or
"l i bag-of-goodies" (look in)

and many many other possibilities where doing an alias that sends "put * bag-of-goodies" just won't really cover everything for me, is there any way to set it up to replace an 'alias' of sorts (say 'bag') with 'bag-of-goodies' in any line of text I happen to type in and send to the mud?

If not, this would be a pretty kewl feature if used carefully..
USA #1
umm.. actually would regex work for this as an alias? like

* (bag) *

would send to the mud

%1 bag-of-goodies %2

..and would this also cover if there was no value for %2?

..actually I may have answered my own question.. best I log on and test it :)
USA #2
nope that didn't work.. also using

* bag *

%1 could be more than one word, as could %2, or indeed %2 could be no words at all...
USA #3
First off. In regexp * mean only 'one or more of', you need to tell it 'what' you want it to find one of more of. This means that .* is the same thing as * in a normal trigger, since '.' tells it to look for 'anything'.

This means that you trigger would need to be:

.* (bag) .*

However, none of this will do what you are looking for. However, using a regular expression, you may just have to do:

<alias>
match="bag"
regexp="y"
enabled="y"
<send>
bag-of-goodies
</send>
</alias>

I am not sure of this though. It should in thery replace any instance of 'bag' with bag-of-goodies. This could however cause issues.

An alternative is this:

<alias>
match = "^(put .*|l i) bag"
regexp="y"
enabled="y"
<send>
%1 bag-of-goodies
</send>
</alias>

This 'should' match on:

put <someitem> bag
l i bag

or anything else you add with another "|" between the items. This will allow you to add as many commands for the bag into the alias as you like.

It is a very good idea when you start playing with regular expressions to actually read the docs on them. If you are making such elementary mistakes as using * instead of .*, then you will have serious trouble getting them to work right. Also, in regexp, a word by itself is just that, a word. Unlike in normal triggers and aliases, there is no automatic implied start or end of line, to make it 'not' match on any part of the like actually requires telling it to look for the start '^' or end '$' of a line. ;)
Australia Forum Administrator #4
Read this post. It is about almost exactly the same thing ...

http://www.gammon.com.au/forum/?bbsubject_id=3129
Amended on Thu 28 Aug 2003 06:58 AM by Nick Gammon
USA #5
Thanks Shadowfyr. The second option works, but I'm trying to get away from using multiple aliases to do it. I actually put in
^(.*?) \(bag\) (.*?)$
on the alias, but just didn't bother typing all that in on here :)

Cheers Nick, going to check that thread now :)


minutes later..

Yup gotchya Nick. The 3 aliases will be the way to go, just wondered if there was another option, but it could be too dangerous going by what Meerclar wrote. I'll be using a variable with it too as that container name can very occasionally change when pthiefs are around :)

Thanks for help!
Amended on Thu 28 Aug 2003 07:10 AM by Guest1
Greece #6
Or, my personal favorite, put bag-of-goodies in the tab completion box and type "ba" and press tab...
USA #7
We have 'restring tokens' on the mud I play, so I solved the 'problem' by renaming the eq to something entirely different (Bag of the Infinitely Prolonged) and changed the ID word for it to 'bag' :)