Wait and Wait Line

Share your scripts and packages with other Mudlet users.
Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Wait and Wait Line

Post by Jor'Mox »

So, if I'm reading things correctly, this should be the same script I wrote above, but changed to use the wait functionality. Probably a bit more intuitive for someone not used to recursion.
Code: [show] | [select all] lua
perform = perform or {}

local performance = performance or {}

perform.run = function(time, rand, song)
    time = time or 1
    rand = rand or false
    song = song or 1
    coroutine.wrap(function()
        for i,v in ipairs(performance[song]) do
            send(v)
            if i < #performance[song] then
                wait(rand and math.random(time) or time)
            end
        end
    end)
end

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

perform.add = function(text, line, song)
    song = song or 1
    performance[song] = performance[song] or {}
    line = line or #performance[song] + 1
    table.insert(performance[song],line,text)
end

perform.remove = function(line, song)
    song = song or 1
    performance[song] = performance[song] or {}
    line = line or #performance[song]
    table.remove(performance[song],line)
end

perform.clear = function(song)
    song = song or 1
    performance[song] = {}
end
Edit: Tweaked the script a bit to allow it to store multiple performances that can be run on command. Note that these can be hard coded into the script if desired, with each performance being a table of strings as one element of the performance table. Like this:
Code: [show] | [select all] lua
local performance = performance or {
    {   "Row row row your boat",
        "Gently down the stream",
        "Merrily merrily merrily",
        "Life is but a dream"},
    {   "Twinkle twinkle little star",
        "How I wonder what you are",
        "Up above the world so high",
        "Like a diamond in the sky",
        "Twinkle twinkle little star",
        "How I wonder what you are"}
}
Just note that the script just sends whatever is in the string, so no doubt you need some sort of game command to use with it. I just didn't bother writing all that out, since I'm pretty sure no one is singing those nursery rhymes in their games.

Post Reply