• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Lua - Lua Functions in parallel instead of in sequence?

Joined
Mar 19, 2021
RedCents
10,291¢
When the code below is started, a() runs right away, then after 5 seconds b() runs, and then after 5 more seconds c() runs. And then it repeats.

time 1: a
time 5: b
time 10: c
time 15: a
time 20: b
etc.

What I want to happen is that a(), b(), and c() all start at the same time, and then each repeat every 5 seconds.
I simply want to delay the repetition of each function without making the other functions wait.

time 1: a,b,c
time 5: a,b,c
time 10: a,b,c
etc.

Is there a way to achieve this?

Lua:
local mq = require('mq')


local a = function()
    print('One')
    mq.delay(5000)
end

local b = function()
    print('Two')
    mq.delay(5000)
end

local c = function()
    print('Three')
    mq.delay(5000)
end

local terminate = false
while terminate == false do
    a()
    b()
    c()
end

In Macro, these would all start at the same time instead of waiting for each line to finish:
/timed 5s /docommand1
/timed 5s /docommand2
/timed 5s /docommand3
 
Last edited:
I am not 100% sure, but my way to view the processing of Lua is, that one Lua has one "processing-queue". If you want to run 3 different things contemporary you either need to implement multithreading or run 3 different Lua's.
Real multithreading may be above what you need. Can you achieve your goals by simply splitting the code in 3 different luas and start all 3 of them?
 
Well, not literally at the same time, but this would work:
Lua:
local mq = require('mq')

local a = function()
    print('One')
end

local b = function()
    print('Two')
end

local c = function()
    print('Three')
end

local terminate = false
while terminate == false do
    a()
    b()
    c()
    mq.delay(5000)
end

This works so long as the delay is the same. Can do the same thing with varying delays, but you would need to add some additional data structures.
 
Lua - Lua Functions in parallel instead of in sequence?

Users who are viewing this thread

Back
Top
Cart