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. :)
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!)
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:
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?
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
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.
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? >.>
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.