So what I'm trying to do is a form of http://www.gammon.com.au/forum/?id=4957 but the specifics are confusing me... Not sure what to put into the regexp line. Here's what the prompt looks like normally:
Quote: <1095/10100CN 100/100SP 0ST 0MT 0DT 0LG 1516XP 1:19 AM (north)>
I'm trying to pause re-enabling my trigger until it triggers the last command that has been sent, so it doesn't trigger 5 times in a row... My old 'solution' was to do a wait.time for several seconds and hope it would work, but that's not really reliable, so... Here's what a sample prompt line might look like with a command. It will always have either You or you in it, but there's no real guarantee where in the statement the 'You' will come. Also, other messages that happen and people who chat will often use 'You' and I'm trying to avoid having it trigger on those.
Quote: <1055/10100CN 100/100SP 0ST 0MT 0DT 0LG 1516XP 12:38 AM (south)> You maneuver down the stairs carefully.
I only want to do the command once, and wait for it to trigger, so I'm not sure if I'm actually doing it right with the repeat and so on. What I'm thinking is that it should be something like this...
Quote: require "wait"
function cr ()
repeat
Send "maneuver stairs"
line, wildcards =
wait.regexp ("^(\<.*CN.*SP.*ST.*MT.*DT.*LG.*XP.*[Yy]ou.*)$")
until string.find (line, "[Yy]ou")
-- wait a second for luck
wait.time (1)
Note ("maneuvering done!")
end -- of function cr
wait.make (cr) -- start coroutine up
Where I'm really confused is the combination of the regexp in wait.regexp and the until string.find part. Do I need both? What's the purpose of each? If I understand properly, your example is looking until it doesn't match because of the caret, right? I haven't used the "repeat" function much and it doesn't appear to be documented in the helpfiles... Should my example skip any line that doesn't match the regexp with no result, and if it does match to look if it has that value in string.find? Does it repeat the command, or only if it does match the regexp and doesn't succeed in the string.find?
This seems like a truly awesome ability, and I'm just wanting to do things properly. Much better than trying to set global variables and have other triggers enabling and disabling themselves all over the place...
Also, the maneuver stairs example is quite a bit shorter than what I'm actually doing... the actual maneuvering bit is about 70 lines long, but that whole thing goes where the send is, and will only fire once, right?
I'd be testing this online, but my connection is too flaky right now for mudding (sad that as my connection has becoming faster, the stability has gone down) but I can work through a plan for the various triggers once it cooperates again. |