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
➜ General
➜ Triggers or Script
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Thu 08 Mar 2007 07:45 PM (UTC) |
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 | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #1 on Thu 08 Mar 2007 08:34 PM (UTC) |
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. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #2 on Thu 08 Mar 2007 08:47 PM (UTC) |
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 | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Fri 09 Mar 2007 12:28 AM (UTC) |
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 | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #4 on Fri 09 Mar 2007 06:02 AM (UTC) |
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. | 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,751 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top