sendQueue function

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

sendQueue function

Post by Jor'Mox »

I had some people asking for a way to send a series of commands that may need to be spaced out time wise so they could do scripted behaviors. In case anyone else wants it, here it is.
Code: [show] | [select all] lua
local runQueue
function runQueue(tbl)
    local info = table.remove(tbl,1)
    if info then
        local run = function()
                send(info[2])
                runQueue(tbl)
            end
        if info[1] ~= 0 then
            tempTimer(info[1], run)
        else
            run()
        end
    end
end

function sendQueue(...)
    local tbl = {}
    local args = arg
    for k,v in ipairs(args) do
        if k % 2 == 1 and type(v) ~= "number" then
            table.insert(args,k,0)
        end
    end
    for k = 1,#args,2 do
        tbl[(k + 1) / 2] = {args[k],args[k+1]}
    end
    runQueue(tbl)
end
Just pass the function commands as if it were sendAll, but if you want to wait before the next command, then pass a number equal to the amount of time you want to wait, and then pass the command. Like this: sendQueue("command 1",2,"command 2") Which would send "command 1" first, then wait 2 seconds, and then send "command 2".

chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: sendQueue function

Post by chrio »

Thanks for sharing. It's nice that it handles fractions of seconds aswell.

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: sendQueue function

Post by Duugan »

chrio wrote:Thanks for sharing. It's nice that it handles fractions of seconds aswell.
I agree. It sounds awesome, but I'm a self-taught (with forum help) novice that will never understand scripting enough to even attempt this table nonsense. :D

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

Re: sendQueue function

Post by Jor'Mox »

Duugan wrote:
chrio wrote:Thanks for sharing. It's nice that it handles fractions of seconds aswell.
I agree. It sounds awesome, but I'm a self-taught (with forum help) novice that will never understand scripting enough to even attempt this table nonsense. :D
That is why I shared this. There is no need to understand tables in order to take advantage of this function, just pass it the commands and delays you want, and it takes care of the rest.

User avatar
Belgarath
Posts: 232
Joined: Fri Jul 26, 2013 7:19 am
Discord: macjabeth#7149

Re: sendQueue function

Post by Belgarath »

Nice. Not sure how many people still use CMUD these days, but this would be a nice and easy substitute for the #wait function they have.

Post Reply