For example, if there is one troll:
Window:
There is a troll here.
Trigger:
There is a (\w+) here.
Action:
send("attack " .. matches[2])
Works just fine to kill one troll. But where there are two, three, four, etc:
Window:
There are two trolls here.
Trigger:
There are two (\w+) here.
Action:
send("attack " .. matches[2])
Will send "attack trolls" with the 's' on the end and the game responds with "You don't see 'trolls' here".
How do I make it only grab the first few characters like tro, trol, or troll, instead of the entire word?
Thanks for any help
How do I get a certain number of characters in a variable?
Re: How do I get a certain number of characters in a variabl
You might consider shifting the regex up a bit.
There are (\w+) (\w+?)s? here\.
Should match whether there are two or fifteen... won't match on fifty two or fifty-two. Don't know if you need it to be that flexible or not. You could also set up a table to translate "two" into 2 an so forth. The second part just strips the s if it's pluralized.
To answer the original question though:
There are (\w+) (\w+?)s? here\.
Should match whether there are two or fifteen... won't match on fifty two or fifty-two. Don't know if you need it to be that flexible or not. You could also set up a table to translate "two" into 2 an so forth. The second part just strips the s if it's pluralized.
To answer the original question though:
Re: How do I get a certain number of characters in a variabl
Okay the (w+)s works to grab "troll" out of "trolls" but when a phrase like "two stone giants" comes up, it won't grab "stone" because there's no S.
I'm having a difficult time understanding lua characters of ^ , ? , * , \ , etc.
I can't seem to find these in the manual either.
I'm having a difficult time understanding lua characters of ^ , ? , * , \ , etc.
I can't seem to find these in the manual either.
Re: How do I get a certain number of characters in a variabl
I fixed it by having both these lines:
There (is|are) (a|an|two|three|four|five|six|seven|eight) (\w+)
There (is|are) (a|an|two|three|four|five|six|seven|eight) (\w+)s
So now it trigger on "There are two orcs" for attack orc, and "There are two stone giants" for attack stone.
Thanks for your help!
There (is|are) (a|an|two|three|four|five|six|seven|eight) (\w+)
There (is|are) (a|an|two|three|four|five|six|seven|eight) (\w+)s
So now it trigger on "There are two orcs" for attack orc, and "There are two stone giants" for attack stone.
Thanks for your help!
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: How do I get a certain number of characters in a variabl
Don't forget that mayhaps you might also need to consider other plural forms, for instance "es"! The only examples I can think of off the top of my head are "finches" and "wenches" - and, whilst I doubt there are too many MUDs with small seed eating killer birds, there could be one or two that have humanoid females that can get aggressive under some circumstances...
Re: How do I get a certain number of characters in a variabl
I have run across "Cyclopes", which is suprisingly the correct plural form.
Re: How do I get a certain number of characters in a variabl
You also have completely irregular plurals, like children, mice, and deer.
Re: How do I get a certain number of characters in a variabl
So yeah... some of them you won't catch with one or two very simple triggers.
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: How do I get a certain number of characters in a variabl
And that is what makes script (and code) writing, um, interesting as in the manner of the Chinese curse.
Re: How do I get a certain number of characters in a variabl
Don't forget the meece... mooses... moose. W/e