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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  Sharing Basic (little) Optimized Aliases

Sharing Basic (little) Optimized Aliases

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


Posted by Marco   (36 posts)  [Biography] bio
Date Fri 29 Sep 2017 01:34 PM (UTC)

Amended on Sat 30 Sep 2017 06:44 AM (UTC) by Marco

Message
(Edit) Would like to share my late experience.
Not really something difficult but quiet useful.

Usually just after you get your MUSH client on your PC, you throw your aliases in bulk, careless, with the only aim to start playing.

After a while you have the Alias windows in such a mess.

Look at mine.

I had:

kka - cast 'protection from acid'
kkab - cast 'protection acid breath'
kkc
kkcb
kke
kkeb
kken
...
kkf - cast 'protection from fire'

I had NINE! All perfectly equal but for the string in the casting.
oh, yes, it works. Works well, But you guess.. even if MUSH is really fast, you can bet having thousands of alias (even though anyone is quiet simple) not different having few better organized with a little of scripting.

So..
What we have...
All the aliases start with kk followed by one or two letters (not any number).

Why don't use the Regular Expression Power even in the alisases?
So i checked the Regular Experssion box and i put:

 ^kk(\w{1,2})$ 

i changed the   ' Send To '   putting   Script   and i also checked " Omit from output "

  ' \w '   means a single "word" character; the   {1,2}   is the quantifier that specify minimum 1, maximum 2.

In the code window i wrote:

  local prot = {
  a = "from acid'",
  ab = "acid breath'",
  c = "from cold'",
  cb = "frost breath'",
  f = "from fire'",
  fb = "fire breath'",
  e = "from electricity'",
  eb = "electric breath'",
  en = "from energy'",
  }  -- end of prot
local P = prot ["%1"]
if P ~= nil then
  print ("cast 'protection " .. P)
  Send ("cast 'protection " .. P)
end -- if   

Useless to say it works very well and it's very fast.
note the   "%1"   --> %1 inside the quotation marks

Is it all?
As a cleric named   Eldanoth   i have several cure spells.

my cure spells aliases were:

h1 - cast 'minor heal'
h2 - cast 'heal'
h3 - cast 'healing'

so when i want to cure my companion i write:

h2 *companion name* - more or less: cast "heal" %1

At a point i liked the idea that:

1) if i don't put the name %1 the spell is cast on me

2) if i'm in a group engaged in combat, not putting any %1 after   h2   will heal the   Tank  . That's very useful! Over all when you battle MOB that Switch from one target to another! Means you cure Always the Right target keeping typing simply   h3   or whatever.

3) ..but if i'm the tank, send also a "Stand" command (even though i have a "Stand" trigger that works well in 90% of the cases, you really don't know)

4) if, for any reason and in any of the above situations i define   "%1"  , then he is healed instead

The Outcome is that i simply write   h3   (or h2 or h1) and the spell is cast onto the target specified by the condition i find myself.

so we have   h   followed by   one   digit.

the Regular Expression to define the Alias is:

 ^\s?h(\d)\s?(.*?)$ 

As you can see i put an optional space in the beginning
It come in hand when you put the alias just after a   ;   to make a whole string of command, separated by a space. (...)

Before to post the code i have to explain that the MUD i'm playing with is called " Tempora Sanguinis ".

In the   variables   page, withing the mxp variables there is one very interesting:
-   mxp_tstank  .

The value is:
- "*" when there is NO tank
- "name of the tank" when someone is tanking

Remember you have to check the box Expand variables to let the variable be read.

So...

local Cura = {"minor heal' ", "heal' ", "healing' "}
local C = Cura[%1]
if C ~= nil then
  if "%2" == "" and "@mxp_tstank" == "*" then
     Send("cast '" .. C .. "eldanoth")
  elseif "%2" ~= "" then
     Send ("cast '" .. C .. "%2")
  else
     if "@mxp_tstank" == "Eldanoth" then Send ("stand") end
     Send ("cast '" .. C .. "@mxp_tstank")
     print ("      - - - - -      Tank route      - - - - -")
  end -- if
end -- if

in this case please pay attention at local variable "C"

local C =   [%1]  

So %1 - WITHOUT - quotation marks because the value got from the first wildcard let you access the array (oops, table) specifying the element you want to pick.

And that's all.
I could've taken the whole range of Cure spells, ranging from "Cure light wounds" to the top, simply increasing the members of the table.

I dedice to share after reading the interesting post on how to delete the last word.
Clever!

ANY FURTHER SUGGESTIONS? --- please, feel free to comment add / criticize ---
[Go to top] top

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #1 on Sat 30 Sep 2017 06:32 AM (UTC)

Amended on Sat 30 Sep 2017 06:51 AM (UTC) by Marco

Message
(edit) Some Punctualisation on the above..

Speaking about the first Alias i wrote
 ^kk(\w{1,2})$ 
and explained   \ w is used to specify a character (not any number).

It's not correct.   \w also include numbers; more ore less like class [a-z0-9A-Z] .

Second thing... since our aim (when we write a trigger or an alias) is the performance, is it good to be much more specific or, instead, be as less as possible?

Look. Every one of the two alias come along with a script in which   if - then checks are done.
I wonder.. the same alias should be written as simple as possible to guarantee the max performance (even though, most probably, we are talking about few hundredth of thousandth of second). Nick, Fiendish, could you confirm?

So, following this path, i'd rewrite the aliases like that:
 ^kk(..?)$ 
for the first one, and for the second instead of;
 ^\s?h(\d)\s?(.*?)$
i'd rewrite it like
 ^\s?h(.)\s?(.*?)$ 
leaving the script and the table within to match whatever is coming. In fact, in the first alias the table come along with keys (a = "from acid'", ab = "acid breath'", ..., ...) and a   if - then check if P is nil or not.

The answer is hidden in the question:

Which of the two (the regular expression parsing or the script execution) are the faster?

Make a more selective regular expression to make sure the scripting start working only when it's needed or start it anyways and let the script make its checks?

I have to say that regarding the Aliases i think better write a quicker regular expression.
Is it not true that you know well and will insert the specific string to trigger exactly what you want?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 01 Oct 2017 10:56 AM (UTC)

Amended on Sun 01 Oct 2017 10:58 AM (UTC) by Nick Gammon

Message
In terms of speed, both will be so fast the difference won't be noticeable. For one thing, your typing speed will be thousands of times slower than what a script can execute at. Things like the mapper module draw hundreds of rooms, each one taking quite complex calculations, virtually instantaneously.

There is an example of how fast the mapper is here.

- Nick Gammon

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

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #3 on Sun 01 Oct 2017 02:14 PM (UTC)

Amended on Sun 01 Oct 2017 04:04 PM (UTC) by Marco

Message
Nick Gammon said:

In terms of speed, both will be so fast the difference won't be noticeable. For one thing, your typing speed will be thousands of times slower than what a script can execute at. Things like the mapper module draw hundreds of rooms, each one taking quite complex calculations, virtually instantaneously.

There is an example of how fast the mapper is [url=https://vimeo.com/80318832?autoplay=1]here[/url].


The mapper is impressive! I cannot imagine what a real programmer like you can do with the scripting tools...

I'm surprised about the speed MUSH client execute the commands. Have you ever banchmarked it (only for your personal knoledge)?

There is some sort of "pre-compiling" or the scripting and all the rest is simply interpreted?

Many compliments for your hard work here.

i would like to ask you something if you let me.

In this forum i found the most beautiful, elegant, awesome, complete and even way much more than average user can need BUTTONS set guide (those that also functions as graphical bars): INCREDIBLES.

i found strange you didn't create a simple wizard to create simple buttons directly in the command bar.

To be clear: it's a really unnecessary feature that i used only to change dress to better match the imminent encounter and those you implemented in the PLUG IN are way superior.

Template:post=9359 Please see the forum thread: http://gammon.com.au/forum/?id=9359.


But Still, i'm curious.. :)
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 03 Oct 2017 07:30 AM (UTC)
Message
I decided to freeze the interface of the client (ie. the menus, dialogs etc.). This has some good points:


  • If someone translates the resource file (the thing with the dialogs in it) into another language (eg. Chinese) then those translated files are good for a long time. If I kept changing the interface, translated versions would need to keep changing.

  • Users get to know where things are (unlike, say, Microsoft Word which seems to keep changing how you interact with it).


The downside is that I can't add new GUI features.

- 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.


17,139 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]