Wait and Wait Line

Share your scripts and packages with other Mudlet users.
nowhereman
Posts: 3
Joined: Fri Feb 19, 2021 7:01 am

Re: Wait and Wait Line

Post by nowhereman »

I've changed:

Code: Select all

function wait_line_timer(name)
    for _,v in ipairs(threads[name][2]) do
        if v ~= nil and v[1] ~= nil then
          disableTrigger(v[1])
          killTrigger(v[1])
        end
    end
    wait_line_resume(name)
end
as when the triggers would fail to resolve their regex the timers would expired and next time I got a successful trigger, i'd get multiple triggers stacking up. It's a quick fix. I think it might be correct. Submitting here as both a bug report and a proposed solution.

-Nowhere.

zhenzh
Posts: 68
Joined: Fri Apr 17, 2020 2:23 am

Re: Wait and Wait Line

Post by zhenzh »

You are correct. Timeout function doesn't point to the correct trigger id.

But your fix can only process single line case, I have fixed it to afford both single line and multiple line cases:

Code: Select all

function wait_line_timer(name)
    for _,v in ipairs(threads[name][2]) do
        for _,i in ipairs(v) do
            disableTrigger(i)
            killTrigger(i)
        end
    end
    wait_line_resume(name)
end
The new version with the fix is uploaded, you can download it from the link in #1 post

tyst8
Posts: 1
Joined: Sun Jul 17, 2022 5:10 am

Re: Wait and Wait Line

Post by tyst8 »

hi, does this still work on mudlet v 4.16.0? I downloaded from post #1 and made this code

Code: Select all

coroutine.wrap(
  function()
    while true do
      local result = wait_line([[^You killed (.{0,4}]],2)
      if result[2] then
        cecho("\n<orange>we killed: " ..result[2])
      end
    end
end)()
and calling this function from a trigger:

Code: Select all

function enemyStatus(target,t)
    result = wait_line([[^You killed (.{0,4}]],t)
    
    if result[2] == target then
        return true
    else
        return false
    end
    
end

both are giving me this error about attempt to index local 'result':
wait_line(): [string "Alias: alias - test"]:5: attempt to index local 'result' (a boolean value)
details: stack traceback:
[string "Alias: alias - test"]:5: in function <[string "Alias: alias - test"]:2>
Last edited by tyst8 on Sun Jul 17, 2022 5:17 am, edited 2 times in total.

Vagonuth
Posts: 2
Joined: Tue Nov 22, 2022 8:31 pm

Re: Wait and Wait Line

Post by Vagonuth »

First off, thank you for this module! It's incredibly helpful.

I was wondering if anyone had a way of making it so a function with a wait() in it could be called and delay what it returns. For example:

Code: Select all

function foo()
  coroutine.wrap(
    function()
      wait(3)
      return "bar"
  end)()
  return "sadface"
end

print(foo())

> sadface
In this example, it will print "sadface". However, it would be nice to have the functionality in that the called to foo would be delayed for 3 seconds and then it prints "bar". I suspect this is possible with the way its implemented but wanted to check.

zhenzh
Posts: 68
Joined: Fri Apr 17, 2020 2:23 am

Re: Wait and Wait Line

Post by zhenzh »

@Vagonuth
I think you may get something misunderstood. The wait module uses coroutine suspend/yield function to implement the action WAIT. So, it requires all your codes are included by an overall coroutine.

In your example, the foo() and print() function will not be correctly controlled by the wait module as they are not in the same coroutine. The coroutine.wrap() you called impacts on the code return "bar" only.

Maybe you can try code below:

Code: Select all

coroutine.wrap(function()

function foo()
    wait(3)
    return "bar"
end

print(foo())

end)()

zhenzh
Posts: 68
Joined: Fri Apr 17, 2020 2:23 am

Re: Wait and Wait Line

Post by zhenzh »

@tyst8
does this still work on mudlet v 4.16.0?
Should work, the module is composed with pure lua code which should not be impacted on the release update of mudlet, unless tempTrigger() and tempTimer() get incompatible.
wait_line(): [string "Alias: alias - test"]:5: attempt to index local 'result' (a boolean value)
Since the wait_line() returns false when match failed, I guess your regext pattern may doesn't work for your trigger line.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Wait and Wait Line

Post by demonnic »

In general, Mudlet works hard not to break backwards compatibility.

I think the issue is your pattern is missing the closing parenthesis to end the capture group.
Code: [show] | [select all] lua
[[^You killed (.{0,4})]]
-- instead of
[[^You killed (.{0,4}]]

yviene
Posts: 1
Joined: Wed Nov 22, 2023 6:37 pm

Re: Wait and Wait Line

Post by yviene »

I have a use case for the wait line function. I want to be able to tell a story or sing a song. It would be cool to launch an alias 'sing fun song' and the song starts and echos into the room the following:

sing (softly in little more than a whisper, in a sweet voice) Hush, little maiden, close thine eyes
[wait line here with a pause of a random 1 to 5 seconds]
sing (softly in little more than a whisper, in a sweet voice) As the silver moon doth
[wait line here with a pause of a random 1 to 5 seconds]
sing (softly in little more than a whisper, in sweet voice) In slumber's embrace, thou shall rest
[wait line here with a pause of a random 1 to 5 seconds]
sing (softly in little more than a whisper, in a sweet voice) In dreams, thy heart shall be blessed
[end]

And then I have a story to tell that would be similar functionality. Except I want to be able to use the timer tool to tell the story each ten or fifteen minutes.

Thank you!!

Jor'Mox
Posts: 1149
Joined: Wed Apr 03, 2013 2:19 am

Re: Wait and Wait Line

Post by Jor'Mox »

So, while something like a wait function is convenient, it isn't overly complicated to do the same thing with the tools already available. For instance, I put together a very simple little script to manage that performance you mention. It just needs a couple of simple aliases thrown together to interface with it, and you would be good to go.
Code: [show] | [select all] lua
perform = perform or {}

local performance = performance or {}

perform.run = function(line, wait, rand)
    line = line or 1
    wait = wait or 1
    rand = rand or false
    send(performance[line])
    if line < #performance then
        tempTimer(rand and math.random(wait) or wait, perform.run(line + 1, wait, rand))
    end
end

perform.view = function()
    for i,v in ipairs(performance) do
        echo("    " .. v .. "\n")
    end
end

perform.add = function(text, line)
    line = line or #performance + 1
    table.insert(performance,line,text)
end

perform.remove = function(line)
    line = line or #performance
    table.remove(performance,line)
end

perform.clear = function()
    performance = {}
end
If you look, you will notice that it uses the tempTimer function and a recursive call to mimic the functionality of a wait function. And, you have the option of either coding in your performance, or adding it line by line via a simple alias that uses the perform.add function.
Last edited by Jor'Mox on Fri Nov 24, 2023 4:49 pm, edited 1 time in total.

zhenzh
Posts: 68
Joined: Fri Apr 17, 2020 2:23 am

Re: Wait and Wait Line

Post by zhenzh »

It's very easy defining an alias to invoke a coroutine function like:

Code: Select all

coroutine.wrap(function()
    <sing or say>
    wait(math.random(1, 5))
    <sing or say>
    wait(math.random(1, 5))
    <sing or say>
end )

Post Reply