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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Building it up with Lua
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Building it up with Lua

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


Posted by BlueEyes   (28 posts)  [Biography] bio
Date Sun 16 Aug 2009 09:33 PM (UTC)
Message
Alright I'm trying to make my base curing script completely off of Lua, I've tinkered around a bit but I'm ready to go head strong into it. I've read the help scripting files Nick placed up so kindly and I can do all those type of things. Now what I am concentrating on is pure speed and I'm debating should I do triggers in Lua tables, or how should I go about beginning to start this. I also don't understand how to call triggers from a table, but any help will be greatly appreciated.
[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 16 Aug 2009 10:05 PM (UTC)
Message
I'm not sure how you would "do triggers in Lua tables" exactly.

Trigger matching in general is quite fast - unless you have tens of thousands of triggers the client will keep up.

A couple of things you can do to help it:


  • Give a trigger that is likely to match often (eg. a prompt) a lower sequence number and do *not* check "keep evaluating". That way, the common case is quickly matched, and the other triggers are not checked.

  • Another post I found seems to indicate that, within reason, a big trigger is faster than lots of small ones. For example:

    
    ^You are afflicted by blindness\.$
    ^You are afflicted by dizziness\.$
    


    Compared to:

    
    ^You are afflicted by (blindness|dizziness)\.$
    


    The second one could be slightly faster (one trigger rather than two).

  • If you want to use Lua tables, and if the messages are fairly generic, you could match something and then do a table lookup, eg.

    
    ^You are afflicted by (.*)\.$
    


    Now lookup the wildcard in a Lua table (where the wildcard is the key), and that would be very fast, even for hundreds of afflictions. Note that I say "the wildcard is the key" which means the table is keyed by the affliction, you don't do a linear search of the table.


That should help get you started.


- Nick Gammon

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

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #2 on Sun 16 Aug 2009 11:41 PM (UTC)

Amended on Sun 16 Aug 2009 11:42 PM (UTC) by Blainer

Message
This is not tested but just to give you some ideas.

<triggers>
  <trigger
   enabled="y"
   match="^You are afflicted by (blindness|dizziness)\.$"
   send_to="12"
   sequence="100"
  >
  <send>
afflicT =   {
            ["disease"] = "cast cure",
            ["poison"] = "cast cure",
            ["curse"] = "cast uncurse",
            ["blindness"] = "cast seebetter",
            ["dizziness"] = "cast stable"
            }
SendNoEcho (afflicT[tostring (%1)])
  </send>
  </trigger>
</triggers>

[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 16 Aug 2009 11:58 PM (UTC)
Message
Make that:


SendNoEcho (afflicT["%1"])


Wildcards *are* strings, but not quoting them is a problem.


- Nick Gammon

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

Posted by BlueEyes   (28 posts)  [Biography] bio
Date Reply #4 on Mon 17 Aug 2009 03:51 AM (UTC)
Message
So I havn't started coding it but I would make the table and when I would have said affliction it would look up that specific table?
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #5 on Mon 17 Aug 2009 04:51 AM (UTC)

Amended on Mon 17 Aug 2009 05:41 AM (UTC) by Blainer

Message
Yes you could write a table with each of the afflictions as the keys and the what to send to MUD when you have that affliction as the value.

"%1" will be the affliction. So that is used to go straight to the value you want in the table instead of iterating the entire table.

Example:

My trigger: ^You are (.*).$

MUD sends: You are sick.

Trigger fires because a match is found.

%1 is now sick because it's in the first set of brackets.
The script in my trigger has a table:

table = {
     ["sick"] = "cast cure",
     ["ugly"] = "think positive"
     }

Sick and Ugly are the keys and cast etc are the values you get when you reference those keys.

If I say:

print (table["sick"])

I get:
cast cure

So now I can simply tell MUSH to send the MUD what ever is in the table for that affliction.

SendNoEcho (table["%1"])
[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Mon 17 Aug 2009 05:38 AM (UTC)
Message
If you amend a post and add tags, when "forum codes" was not checked, it doesn't automatically turn them on. I edited the post and checked "forum codes".

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Mon 17 Aug 2009 05:40 AM (UTC)

Amended on Mon 17 Aug 2009 05:41 AM (UTC) by Nick Gammon

Message
The forum has code to detect forum codes and turn them on, with specific codes it checks for, and on an initial post (not an edit). This is because people tended to forget to check "forum codes" when they were obviously required (eg. the post had lots of [code] tags in it).

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


5,836 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 FutureQuest]