[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]  Issue with targeting one word for a variable when line can have multiple words

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Issue with targeting one word for a variable when line can have multiple words
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)

Pages: 1  2 

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Mon 07 Mar 2011 03:03 AM (UTC)  quote  ]

Amended on Mon 07 Mar 2011 03:12 AM (UTC) by Whisk3rz

Message
Nick Gammon said:

Well, mobname = "big fat ugly grave robber" was purely a test case to demonstrate the idea.

Change:


mobname = "grave robber"


to:


mobname = "%1"





OR, I could write all that code I just wrote! Same result, different path, I guess! Thanks again! [And please excuse the double post!!]
[Go to top] top

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Mon 07 Mar 2011 03:01 AM (UTC)  quote  ]
Message
I THINK I HAVE IT!

So far this works perfect for me. I think this is what I was looking for.

Thank you all for your help and it did help. Thanks Nick for the Trigger line, that really pulled it all together once I figured out the if/then statements. Taught me a little bit about this HUGE language I don't know...yet. :-P


<triggers>
  <trigger
   enabled="y"
   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>

--Command to kill robber if match is made
if "%1" == "grave robber" then
Send ("kill " .. "robber")
--Sets target variable to mob for further fighting.
  Execute ("t ".. "robber")
--Displays target in bottom left
SetStatus ("Target: %1")
end --if

--Command to kill imp if match is made
if "%1" == "grave imp" then
Send ("kill " .. "imp")
--Sets target variable to mob for further fighting.
  Execute ("t ".. "imp")
--Displays target in bottom left
SetStatus ("Target: %1")
end --if

--Command to kill zombie if match is made
if "%1" == "zombie" then
Send ("kill " .. "zombie")
--Sets target variable to mob for further fighting.
  Execute ("t ".. "zombie")
--Displays target in bottom left
SetStatus ("Target: %1")
end --if

--Command to flee if match is made
if "%1" == "Master Zombie" then
ColourNote ("black", "red", "RUN FOR YOUR LIFE!")
world.EnableGroup ("HuntGY", 0)
end --if</send>
  </trigger>
</triggers>
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Mon 07 Mar 2011 02:37 AM (UTC)  quote  ]
Message
Well, mobname = "big fat ugly grave robber" was purely a test case to demonstrate the idea.

Change:


mobname = "grave robber"


to:


mobname = "%1"



- Nick Gammon

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

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Mon 07 Mar 2011 01:23 AM (UTC)  quote  ]
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?
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sun 06 Mar 2011 11:02 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sun 06 Mar 2011 11:00 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Sun 06 Mar 2011 09:57 PM (UTC)  quote  ]

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
[Go to top] top

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Sun 06 Mar 2011 09:41 PM (UTC)  quote  ]
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"
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sun 06 Mar 2011 09:23 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Sun 06 Mar 2011 08:50 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Sun 06 Mar 2011 08:40 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sun 06 Mar 2011 08:30 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Sun 06 Mar 2011 08:17 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Sun 06 Mar 2011 07:48 PM (UTC)  quote  ]
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

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Sun 06 Mar 2011 06:53 PM (UTC)  quote  ]
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...
[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.


3,383 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

[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]