It helps combining simple actions to a set of action chain which get your functions modular.
As the functions uses coroutine yield/resume, you have to wrap all your implemention in a coroutine function.
Syntax:
wait(time)
Get your function flow being suspended for specified time.
Parameters
- time: the time in seconds for which to wait
Get your function flow being suspended until the specified pattern line coming. Matche values from regex will be returned.
Parameters
- pattern: string or table regular expression that lines will be matched on, function flow will not go ahead until this pattern is matched.
When using table pattern format, multiple patterns can be specified to simulate waitting multi-line.
Lines will be compared one after another as the sequence of the table. The flow will not go ahead until all patterns are matched.
- timeout: seconds to wait for the pattern line, will resume the coroutine with false returned. 0 for no timeout.
- action: any behavior commands to be sent to server, multiple commands can be accepted with command separator.
Example
Code: Select all
coroutine.wrap(function()
send("say this is a test")
wait(3)
send("say 3 seconds later")
end)()
function kill_enemy(target)
local result = wait_line([[^(\S+) die]], "kill "..target)
if result[2] == target then
return true
else
return false
end
end
coroutine.wrap(function()
if kill_enemy("monster") == true then
send("say job success")
else
send("say job fail")
end
end)()