Addict
Well-known member
- Joined
- Aug 18, 2019
- RedCents
- 570¢
I would like to capture the return value of an event.
Here is a toy example of what I am after:
[CODE title="Lua"]
local mq = require("mq")
local eventSay = function (line, arg1, arg2)
print(arg1)
print(arg2)
return true
end
mq.event("eventSay", "#1# says, #2#", eventSay)
local function test()
local result
while true do
result = mq.doevents("eventSay")
print(result)
mq.delay(5000)
end
end
test()
[/CODE]
I would like result to print true (return value of eventSay) when the event is triggered from the queue. I am able to do something similar in macroscript but I am unsure how to do it in Lua. I *think* I could do it with global variables but I would really like to avoid that if possible.
Just to clarify this is what I mean by globals:
[CODE title="Lua"]
local mq = require("mq")
local result
local eventSay = function (line, arg1, arg2)
print(arg1)
print(arg2)
result = true
end
mq.event('eventSay', "#1# says, #2#", eventSay)
local function test()
while true do
mq.doevents("eventSay")
print(result)
mq.delay(5000)
end
end
test()
[/CODE]
The code above works as expected (result is nil until someone says something and then result is true). I just don't think managing these global flags is the best way but I may of course be wrong.
Any tips and/or tricks?
Here is a toy example of what I am after:
[CODE title="Lua"]
local mq = require("mq")
local eventSay = function (line, arg1, arg2)
print(arg1)
print(arg2)
return true
end
mq.event("eventSay", "#1# says, #2#", eventSay)
local function test()
local result
while true do
result = mq.doevents("eventSay")
print(result)
mq.delay(5000)
end
end
test()
[/CODE]
I would like result to print true (return value of eventSay) when the event is triggered from the queue. I am able to do something similar in macroscript but I am unsure how to do it in Lua. I *think* I could do it with global variables but I would really like to avoid that if possible.
Just to clarify this is what I mean by globals:
[CODE title="Lua"]
local mq = require("mq")
local result
local eventSay = function (line, arg1, arg2)
print(arg1)
print(arg2)
result = true
end
mq.event('eventSay', "#1# says, #2#", eventSay)
local function test()
while true do
mq.doevents("eventSay")
print(result)
mq.delay(5000)
end
end
test()
[/CODE]
The code above works as expected (result is nil until someone says something and then result is true). I just don't think managing these global flags is the best way but I may of course be wrong.
Any tips and/or tricks?
Last edited:

