All of the details for what is going on with wait.lua are in
http://www.gammon.com.au/forum/?id=4956
and
http://www.gammon.com.au/forum/?id=4957
The short version is:
wait.lua does two things.
The first is that it adds a convenience layer on top of DoAfterSpecial (
http://www.gammon.com.au/scripts/function.php?name=DoAfterSpecial ).
The following codes do the same thing, but the second one is much easier to understand:
function do_some_things_with_pauses()
part_a()
end
function part_a()
print("this is part A!")
DoAfterSpecial(5, "part_b()", sendto.script) -- wait 5 seconds then call part B
end
function part_b()
print("this is part B!")
DoAfterSpecial(5, "part_c()", sendto.script) -- wait 5 seconds then call part C
end
function part_c()
print("this is part C!")
end
require "wait"
function do_some_things_with_pauses()
wait.make(function()
print("this is part A!")
wait.time(5)
print("this is part B!")
wait.time(5)
print("this is part C!")
end)
end
The second thing is that it adds a convenience layer on top of AddTriggerEx (
http://www.gammon.com.au/scripts/function.php?name=AddTriggerEx ).
The following code gives you similar readability as above, but with waiting for output from the game instead of for a set amount of time:
require "wait"
function do_some_things_with_waiting_for_responses()
wait.make(function()
print("when my game gets this next command it will respond with 'HELLO'")
Send("send me HELLO")
wait.match("HELLO") -- wait forever for the game to send HELLO
print("My game just responded with 'HELLO'!")
print("when my game gets this next command it will respond with 'GOODBYE'")
Send("send me GOODBYE")
wait.match("HELLO", 10) -- wait for up to 10 seconds for the game to send HELLO
print("10 seconds must have passed, because I was waiting for 'HELLO' but my game never sent it!")
end)
end