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
➜ 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 page
Posted by
| Zylogia
(12 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 16 Mar 2008 08:23 PM (UTC) |
Message
| |
Posted by
| Nick Gammon
Australia (23,133 posts) 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 | Top |
|
Posted by
| Worstje
Netherlands (899 posts) 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. :) | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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:
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 | 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.
16,564 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top