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
➜ Issue with targeting one word for a variable when line can have multiple words
Issue with targeting one word for a variable when line can have multiple words
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| Whisk3rz
(17 posts) Bio
|
Date
| Sun 06 Mar 2011 04:46 PM (UTC) Amended on Sun 06 Mar 2011 04:57 PM (UTC) by Whisk3rz
|
Message
| I'm trying to find a way to set this trigger to target "robber" or "imp" but when there are more than one creature in the room, the line reads like this...
In this room you see: 1st grave robber, 1st grave imp, 2nd grave robber, etc.
When there's only one it reads like this...
In this room you see: 1st grave robber
So how do I isolate "robber" or "imp" without capturing the rest of the line? The first thing I thought was to make a limit on the capture to 3 characters, but I don't know -anything- about coding, so I'm basically teaching myself this stuff as we go. Any help would be appreciated.
Trigger below:
Quote: <triggers>
<trigger
enabled="y"
expand_variables="y"
group="HuntGY"
keep_evaluating="y"
match="^In this room you see\: 1st grave *(.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>--Sets target variable to "grave *" for further fighting.
Execute ("t %1")
--Sends kill command first time via alias "kill"
Execute ("kill")
--Displays target in bottom left
SetStatus ("Target: %1")
</send>
</trigger>
</triggers>
Edit: Version 4.43 | Top |
|
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Reply #1 on Sun 06 Mar 2011 06:45 PM (UTC) |
Message
| Based on your attempt, it looks like you're maybe trying to get this?
^In this room you see\: 1st grave (\w+)
That will put the first alphanumeric sequence following "grave" into %1, ending at the first non-alphanumeric character. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Whisk3rz
(17 posts) Bio
|
Date
| Reply #2 on Sun 06 Mar 2011 06:53 PM (UTC) |
Message
|
Fiendish said:
Based on your attempt, it looks like you're maybe trying to get this?
^In this room you see\: 1st grave (\w+)
That will put the first alphanumeric sequence following "grave" into %1, ending at the first non-alphanumeric character.
Okay, so far that works great. Thank you.
... Now to make it a little more complex. what if "1st zombie" was a possible mob too?
I'm simply trying to find a way to combine this so I don't have 3+ triggers to hit the three + mobs that may be here...
| Top |
|
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Reply #3 on Sun 06 Mar 2011 07:48 PM (UTC) |
Message
| Right now I'm thinking something along the lines of
^In this room you see\: 1st (zombie)|(?:grave (\w+))
The only thing about this pattern is that if it's zombie, then zombie will be in %1, but if it's grave <something> then the something will be in %2 and not in %1. So you'll need to, in your script, check explicitly to see if "%1" == "zombie" and if not then use %2 |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #4 on Sun 06 Mar 2011 08:17 PM (UTC) |
Message
|
Fiendish said:Right now I'm thinking something along the lines of
^In this room you see\: 1st (zombie)|(?:grave (\w+))
The only thing about this pattern is that if it's zombie, then zombie will be in %1, but if it's grave <something> then the something will be in %2 and not in %1. So you'll need to, in your script, check explicitly to see if "%1" == "zombie" and if not then use %2
Make sure you wrap that | in a group (), or it'll alternate between "^In this room you see\: 1st (zombie)" and "(?:grave (\w+))".
^In this room you see\: 1st (?:(zombie)|grave (\w+))
|
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 06 Mar 2011 08:30 PM (UTC) |
Message
| Or, if you are looking for "zombie" or "grave robber" then allow for a space, eg.
^In this room you see\: 1st ([%a ]+)
Now %1 might be "grave robber" or "zombie". And since extra ones have a comma before them, that will terminate the search for characters. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Whisk3rz
(17 posts) Bio
|
Date
| Reply #6 on Sun 06 Mar 2011 08:40 PM (UTC) |
Message
|
Nick Gammon said:
Or, if you are looking for "zombie" or "grave robber" then allow for a space, eg.
^In this room you see\: 1st ([%a ]+)
Now %1 might be "grave robber" or "zombie". And since extra ones have a comma before them, that will terminate the search for characters.
Will it capture "grave robber" that way? I need just robber/imp captured if its one of those two... thank you all for your help. | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #7 on Sun 06 Mar 2011 08:50 PM (UTC) |
Message
|
Nick Gammon said:
^In this room you see\: 1st ([%a ]+)
What is %a? I know \a matches a bell character, but that doesn't make sense either |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #8 on Sun 06 Mar 2011 09:23 PM (UTC) |
Message
| Ooops, sorry I was in "Lua mode". In Lua that would be "an alphabetic character".
^In this room you see\: 1st ([A-Za-z ]+)
Quote:
Will it capture "grave robber" that way?
Try it and see. It should (or the amended one should). Just to explain, inside the brackets are groups of things, like A-Z and a-z for alphabetic characters, upper and lower case. Plus a space so we capture the space between "grave" and "robber". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Whisk3rz
(17 posts) Bio
|
Date
| Reply #9 on Sun 06 Mar 2011 09:41 PM (UTC) |
Message
|
Nick Gammon said:
Ooops, sorry I was in "Lua mode". In Lua that would be "an alphabetic character".
Try it and see. It should (or the amended one should). Just to explain, inside the brackets are groups of things, like A-Z and a-z for alphabetic characters, upper and lower case. Plus a space so we capture the space between "grave" and "robber".
How would I get it to only plug "robber" "imp" or "zombie" when the names are grave robber or grave imp? My game wont accept "kill grave robber" | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #10 on Sun 06 Mar 2011 09:57 PM (UTC) Amended on Sun 06 Mar 2011 09:58 PM (UTC) by Twisol
|
Message
| ^In this room you see: 1st (?:grave )?([A-Za-z ]+)
|
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #11 on Sun 06 Mar 2011 11:00 PM (UTC) |
Message
|
Whisk3rz said:
How would I get it to only plug "robber" "imp" or "zombie" when the names are grave robber or grave imp? My game wont accept "kill grave robber"
That is one of my pet hates.
In this room you see: grave robber
> kill grave robber
There is no grave robber here.
...
There is a silver sword lying here.
> take silver sword
There is no silver sword here.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #12 on Sun 06 Mar 2011 11:02 PM (UTC) |
Message
| More generally (in case it isn't always the word "grave") you can get the last word. For example:
mobname = "big fat ugly grave robber"
last_word = string.match (mobname, "[%a]+$")
Send ("kill " .. last_word)
That sends "kill robber".
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Whisk3rz
(17 posts) Bio
|
Date
| Reply #13 on Mon 07 Mar 2011 01:23 AM (UTC) |
Message
| Okay, so far this is what I have...
<triggers>
<trigger
expand_variables="y"
group="HuntGY"
keep_evaluating="y"
match="^In this room you see\: 1st ([A-Za-z ]+)"
regexp="y"
send_to="12"
sequence="100"
>
<send>--Define mobset prior to running
mobname = "grave robber"
--Checks to see if creature in the room is in mobset and if so, sets the last word of name as "last_word"
last_word = string.match (mobname, "[%a]+$")
--Command to kill mob if match is made from mobset
Send ("kill " .. last_word)
--Sets target variable to mob for further fighting.
Execute ("t ".. last_word)
--Displays target in bottom left
SetStatus ("Target: %1")
</send>
</trigger>
</triggers>
and it works great... for robbers. It's actually -only- trying to kill robbers, even if there are only grave imps in the room, though.
This is a standard set up of what i see when I look:
[Ancient Graveyard]
Paralleling the widening path are empty holes in the ground. The realization that these empty holes once held not only a coffin, but a body, becomes abundantly clear by the broken wood and scattered bone fragments still lying around. The large oak trees that surround these desecrated graves stand silently, their only purpose to drop their leaves and fill in the gaping holes.
The area is illuminated.
In this room you see: 1st grave robber, 1st grave imp, 1st zombie, 2nd grave imp
In this room are: large oak tree
Obvious exits are: northwest, south
Now I want it to ultimately kill any (and all) of these. But I need it to pick one target. But not necessarily just the grave robber. As it's currently set up, if there are only grave imps, it still tries to kill a grave robber... what would I need to do to fix this and make it viable to attack any of those three mobs? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #14 on Mon 07 Mar 2011 02:37 AM (UTC) |
Message
| Well, mobname = "big fat ugly grave robber" was purely a test case to demonstrate the idea.
Change:
to:
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
50,865 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top