Difference between revisions of "Wait and wait line script"

From Mudlet
Jump to navigation Jump to search
(initial creation)
 
m
 
Line 1: Line 1:
 +
[[Category:Mudlet Package Listing]]
 
{| class="wikitable" style="width: 70%;"
 
{| class="wikitable" style="width: 70%;"
 
|-
 
|-

Latest revision as of 07:33, 11 December 2023

Game non-mud specific
By zenzh
Download Mudlet Forums
Dependencies Mudlet 4.17

Description

The script is to implement the result that suspend current function and waiting specified time or pattern coming. It helps combining simple actions to a set of action chain which get your functions modular. As the functions uses co-routine yield/resume, you have to wrap all your implementation in a co-routine function.


Usage

wait(time)
Get your function flow being suspended for specified time.
Parameters
time: the time in seconds for which to wait


wait_line(pattern, timeout[, action])
Get your function flow being suspended until the specified pattern line coming. Matched 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 (optional): any behavior commands to be sent to server, multiple commands can be accepted with command separator.


See also: Mudlet Forums

Examples

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)()