[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Trigger help =/
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Trigger help =/

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Czernobog   (4 posts)  [Biography] bio
Date Wed 19 Nov 2008 03:49 PM (UTC)
Message
Hey everyone, this is my first post. Pretty sure there's a bunch of topics of this nature, so I'll try not to bog it down too much.

I suck at regular expressions and need help making a trigger that will listen for something in the nature of

You can butcher w, x, y and z from name

which will return

butcher w from name
butcher x from name

etc. However, the amount of things butcherable changes-- it's not always 4 like in the example.

Thanks in advance for the help.
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #1 on Wed 19 Nov 2008 05:18 PM (UTC)

Amended on Wed 19 Nov 2008 05:19 PM (UTC) by Worstje

Message
This is one of those things regular expressions alone cannot help you with. However, something along the lines of:

-- This is Lua script.
-- Trigger: ^You can butcher (.*) from (.+)$
items, from = wildcs[1], wildcs[2]
items = items.gsub(" and", ",", 1)

for obj in items:gmatch("%w+") do
  world.Execute("butcher " .. obj .. " from " .. from)
end


The above code assumes you are putting the script in your main scriptfile. If you aren't, but are using the Send To Script functionality, replace the first line by:

items, from = "%1", "%2"


The code is untested and written in three minutes or so, but it should work. Good luck. :)
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #2 on Wed 19 Nov 2008 08:20 PM (UTC)
Message
One small typo I noticed:

items = items.gsub(" and", ",", 1)

--should be

items = items:gsub(" and", ",", 1)
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #3 on Wed 19 Nov 2008 09:49 PM (UTC)
Message
Well spotted. I believe I wrote :replace at first, then realized it was gsub, and put the . down when I deleted too much. (I know I was reminding myself that Lua uses : for member access, but I fubarred it up after all. Oh well!)
[Go to top] top

Posted by Czernobog   (4 posts)  [Biography] bio
Date Reply #4 on Fri 21 Nov 2008 04:40 AM (UTC)
Message
Alright, the script seems like it's semi-working, but I'm getting some major infinite loopage.


[[This part is in the Trigger line]] ^You can butcher (.*) from (.+)\.$

items, from = "%1", "%2"
items = items:gsub(" and", ",", 1)

for obj in items:gmatch("%w+") do
  world.Execute("butcher " .. obj .. " from " .. from)
end


I'm using it in the triggers section since I don't actually have a main script file at the moment. The only things I changed were the errors that you guys noticed with the :gsub part and the "items, from" line, plus I included the \. at the end of the trigger part, because I needed there not to be a period returned with the name of the corpse. I think it was the right way to do it, but, again, infinite loop D:
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #5 on Fri 21 Nov 2008 04:46 AM (UTC)
Message
How are you determining that it's an infinite loop? Are you getting an endless number of executions, for example? That code really doesn't look like it would loop forever. Do you have other triggers that might be triggering in circles?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 21 Nov 2008 04:59 AM (UTC)
Message
I tried this trigger:


<triggers>
  <trigger
   enabled="y"
   match="^You can butcher (.*) from (.+)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
items, from = "%1", "%2"
items = items:gsub(" and", ",", 1)

for obj in items:gmatch("%w+") do
  world.Execute("butcher " .. obj .. " from " .. from)
end
</send>
  </trigger>
</triggers>


I tested it and it seemed to work OK:


You can butcher w, x, y and z from name.
butcher w from name
butcher x from name
butcher y from name
butcher z from name




- Nick Gammon

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

Posted by Czernobog   (4 posts)  [Biography] bio
Date Reply #7 on Mon 24 Nov 2008 08:23 PM (UTC)
Message
Okay, that last one is on the right track, except, first off, my description is off: turns out the message I'm trying to trigger puts a "the" before each argument I'm trying to use, making it like

You can butcher the w, the x, the w and the z from corpsename

and secondly, the previous trigger can't handle when there's spaces in the butcherable item's name.


Sorry that this is needing all the revisions, guys, but I really appreciate the help :D
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #8 on Mon 24 Nov 2008 10:05 PM (UTC)

Amended on Mon 24 Nov 2008 10:07 PM (UTC) by Worstje

Message
This should do what you need it to do.

items, from = "%1", "%2"
items = items:gsub(" and", ",", 1)

for obj in items:gmatch("the ([^,]+)") do
  world.Execute("butcher " .. obj .. " from " .. from)
end


On other words, all that was needed was to adjust the thing I'm trying to match so it excludes the 'the' and starts including spaces. This was done by making 'the' a part of the pattern, and making the variable part put in (parentheses). The [^,]+ means to match everything but a comma once or more, preferably more.
[Go to top] top

Posted by Czernobog   (4 posts)  [Biography] bio
Date Reply #9 on Thu 04 Dec 2008 11:40 PM (UTC)

Amended on Fri 05 Dec 2008 02:24 AM (UTC) by Czernobog

Message
Ah! that was it. Thanks a lot for the help, and for explaining what the stuff meant. I'm a ton more efficient now :D

I have another question now, though, and I really don't want to fill up the board with my own topics, so here it is:

Can I use a timer to start another timer? And can I cause a timer to make itself stop running?

My specific situation is, I'd like to read a book every 16 seconds, but after a number of uses, the book will crumble. Since I don't want to have it spamming "I see no book here" every 16 seconds AND I don't want to have to manually disable the timer each time my book crumbles, I thought perhaps I'd have another timer running at a larger interval than 16 seconds-- perhaps 1 to 5 minutes, or something, to "look bookname" and if it says that I DO have it, then it would begin the shorter timer.

EDIT: Now that I think about it, there'd have to be an intermediate step with triggers. So the small timer would run until the book crumbled, where a trigger would notice that it crumbled and thus enable the larger timer and disable the smaller. The larger timer would just check my inventory, where another trigger would look for the book name, and if it did exist, it would disable the larger and enable the smaller. At least I think that's how it'd work. Does that make sense? >.>
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #10 on Fri 05 Dec 2008 04:29 AM (UTC)
Message
I am a bit sleepy, and your story is a bit confusing to me, but if I understand correctly, you want to read a book every sixteen seconds.

Simply make a timer, call it BookTimer and set it for 16s, make it Send To Script. Use Send("read book") or whatever to read from it.

Now make a trigger that fires on "I see not book" or whatever the message is that you get when a book has crumbled and you have tried to read from it. Send To Script again, this time with the code: EnableTimer("BookTimer", false)

Now you will read your book every 16s when the timer is on, until you run out of a book to read. Additionally, you can make a simple alias that starts the timer for you also.

You will get one fail message this way, but I think that this way is easier and less error-prone than writing a whole script to go through your inventory.
[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.


6,802 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]