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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Processing an alias that might have zero wildcards

Processing an alias that might have zero wildcards

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


Posted by Zylogia   (12 posts)  [Biography] bio
Date Sun 16 Mar 2008 03:46 PM (UTC)
Message
I want to supersede an in-game command, "pose" with an alias of the same name, that does some additional processing. The details of the added stuff probably don't matter for this question.

I've developed a script called fn_pose that works fine. The problem occurs in the calling of the script.

I have defined an alias, pose *

If on the in-game command line I type,
pose <space> <enter>
then the function runs.

If on the command line I type,
pose Several words <enter>
then the function runs fine

However, if I type just
pose <enter>
then the function does not run at all. Rather, the in-game command runs.

I've got a workaround, in that I now have 2 aliases, called pose
pose *

They both call the same function. (I test for nil as a wildcard, and then process OK.)

Now my question: Is there a more elegant solution than using two aliases like this?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 16 Mar 2008 08:23 PM (UTC)
Message
See: http://www.gammon.com.au/forum/?id=8220

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 16 Mar 2008 08:36 PM (UTC)
Message
This question comes up every few months, so I have added it to the FAQ, see http://mushclient.com/faq point 50.

The FAQ item explains the whole thing in a bit more detail and gives a couple of suggestions about different approaches.

- Nick Gammon

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

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #3 on Mon 17 Mar 2008 08:55 AM (UTC)
Message
A little comment to the item you added in the FAQ.. Instead of using {0,1} you can also use ? instead. It means the same and is more commonly used in regular expressions for the 'it may or may not match' situation. Although, I suppose it is mostly a difference in taste. :)
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 17 Mar 2008 07:30 PM (UTC)
Message
That's quite true. Instead of:


match="^heal( {1,}(.*)){0,1}$"


I could have written:


match="^heal( +(.*))?$"


The "+" means "one or more spaces" and the "?" means "zero or one of the previous item/group". That is more compact, and more frequently used, however arguably less clear.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


15,011 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 HostDash]