|
Bromax Wanderer
Joined: 03 Jan 2002 Posts: 66
|
Posted: Fri Mar 19, 2004 11:58 pm
remove words from capture? |
I have a trigger that sets my target's name to a variable (@target)
the problem I have is that the name is often preceded by the words "a" or "the" like: "a deer" or "the snake" and the mud doesn't recognize that name...my question is: Is there some way to remove the words "a" or "the" from the beginning of the text that I caputre? I'm not quite sure how to go about even starting this. |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Sat Mar 20, 2004 2:13 am |
The snake is here.
Something simple to fire of the last word
#TR {(%w) is here.} {target=%1}
Something to get the second word
#TR {(*) is here.} {target=%word(%1, 2)}
Something more complex to get the last word
#TR {(*) is here.} {target=%word(%1, %numwords(%1))}
There are even more complex ways to go like
getting the first word with more than x amount of chars.
or
getting the last word with more than x amount of chars.
But I am way to tired to rack my brain for more examples |
|
|
|
Bromax Wanderer
Joined: 03 Jan 2002 Posts: 66
|
Posted: Sat Mar 20, 2004 4:40 am |
Thanks I got that part...but I am trying to get a more specific target i.e. fat deer vs. skinny deer...instead of deer in general.
|
|
|
|
Dorrin Novice
Joined: 08 Aug 2002 Posts: 41
|
Posted: Sat Mar 20, 2004 11:25 am |
What I've done in the past is to set up the trigger like this:
#tr {{A|An|The} (*) is here.} {target = %1} |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Mar 20, 2004 7:56 pm |
It's fairly easy to remove words from a string.
The %remove function will remove the FIRST occurence.
If it's necessary to remove all occurences, use the %replace function to replace them with a null string.
Functions are usually case-sensitive, so you may want to use %lower to control the case.
In this case, you probably only want to remove "a", "an", or "the" if it's the first word in the string, so a bit more testing is in order.
"The snake" = remove "the"
"Merlin the Magnificent" = don't remove "the"
#VAR target {%if( (%lower( %word( {@target}, 1)) = the) OR (%lower( %word( {@target}, 1)) = a) OR (%lower( %word( {@target}, 1)) = an), %trim( %remove( %word( {@target}, 1), {@target})), {@target})} |
|
|
|
Bromax Wanderer
Joined: 03 Jan 2002 Posts: 66
|
Posted: Mon Mar 22, 2004 7:50 am |
I'm trying to learn this myself so I've simplified it just to the letter a for now...it is in lower case already so I removed that part. I have:
#var target {%if( %word( {@target}, 1)=a)}{%remove( %word( {@target}, 1))} {@target}
target starts as "a fat deer"
this produces {}{} as the result instead of the desired "fat deer"
what did I do wrong? |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Mar 22, 2004 8:03 pm |
Just about everything.
You apparently tried to mix the syntax for %if with the syntax for #IF.
%if has three sections: the condition, the true result, and the false result. You only supplied one, the condition, so it returns nothing (the result you provided for either outcome).
%remove has two sections: the string to be removed and the string to remove it from. You only supplied one, the string to be removed, so it returns nothing (the result of removing anything from a null-string).
The #VARIABLE command has four sections: the name, the value, the default value, and the classname. You provided three: the name, value, and default value, even though there's no reason to give this variable to have a default value. Actually, you got lucky and left out the space between a)} and {%remove, otherwise you would have provided all four sections of the #VARIABLE command and you'd probably be wondering where all the odd CLASSes were coming from too.
All of this is covered quite plainly in the zMUD Help. You'd save yourself a lot of time if you just looked things up instead of waiting for us to tell you what the help says. |
|
|
|
|
|