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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Triggers or Script

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Triggers or Script
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Tsunami   USA  (204 posts)  [Biography] bio
Date Fri 09 Mar 2007 06:02 AM (UTC)  quote  ]
Message
Ok, thanks for the answer. The length and unwieldiness of the trigger is not a problem, since it would have been dynamically created by the script, nor is creating the table, it's essentially read in from a file.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Fri 09 Mar 2007 12:28 AM (UTC)  quote  ]
Message
Quote:

if wordtable.wildcards[1] then
-- blah blah
end -- if


Even that is wrong because it will look for an entry called "wildcards" in your table. You need:


if wordtable [wildcards[1]] then
  -- blah blah
end -- if


- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 08 Mar 2007 08:47 PM (UTC)  quote  ]
Message
I agree with Shaun. I would make a trigger that matches on a word, and then use Lua to lookup in a table. After all, table lookups are fast because they are hashed, whereas the trigger regular expression would have to try one after the other.

Quote:

if wordtable.wilcards[foo] == not nil do


This method still has the problem I mentioned before. "not nil" will evaluate to "true". Thus you would have to store true in each table item for that to work. Better (and shorter) is:


if wordtable.wildcards[1] then
  -- blah blah
end -- if


The other problem here is the tedium of setting up the table, having to give a value to each item. One method is to make a numerically-indexed table, and convert to a keyed index table, like this:


wordtable = { 
  "Lorem", "ipsum",  "dolor",  "sit",  "amet",
  "consectetur",  "adipisicing", "elit" ,
  --- and so on 
  }  -- end of wordtable 

keyed_wordtable = {}

-- do this once - turn table into keyed table

for _, v in ipairs (wordtable) do 
  keyed_wordtable [v] = true 
end

print (keyed_wordtable ["ipsum"])   --> true
print (keyed_wordtable ["occaecat"])  --> nil


The original "wordtable" is simply a list of words - however the disadvantage is you can't do a keyed lookup. The for loop iterates through that and builds a second table, this time with "true" as the value for each entry.

- Nick Gammon

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

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Thu 08 Mar 2007 08:34 PM (UTC)  quote  ]
Message
It would be much simpler to send it to the script. First off, it's easier to keep track of and edit, since it can be broken into smaller chunks to make it more organized. You don't want to have to hunt through a 500 word trigger for one tiny mistake you might make. Secondly, regex is usually kind of slow as a matching system compared with a standard trigger. The fewer options you give it, the better, since it will try to match on every single bit of output it receives.

I personally would just make a table where all the words are keys and pair it with data so that I could have something like this in the script file:

wordtable = { ["word1"] = val1, ["word2"] = val2....}
function matchwords( tname, tstr, wildcards )
  if wordtable.wilcards[foo] == not nil do
    -- insert what you wanted the trigger to do here.
  end -- check for word
end -- matchwords

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Tsunami   USA  (204 posts)  [Biography] bio
Date Thu 08 Mar 2007 07:45 PM (UTC)  quote  ]
Message
I need to match on any of a list of about 500 words. My question is, which is the better (faster) way to do this; with a trigger like (word1|word2|word3|...word500), or with a trigger on (\w+?) that calls a Lua script which checks if the matched word is in a table of the 500 words?

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


2,515 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]