• 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

Question - How to sequence commands...

Joined
Nov 23, 2019
RedCents
1,410¢
Having some fun learning Lua, but ran into this issue. I am trying to make a button to camp my toons. I want everyone to set camp (using MQ2Boxr Camp command) and then set the main tank to tank mode (currently only supporting CWTN). Here is the code:
Code:
        mq.cmd('/squelch /dgga /boxr Camp')
        local command = string.format('/%s mode tank',mq.TLO.Group.MainTank.Class.ShortName())
        sendCommand(command,mq.TLO.Group.MainTank.Name())
This code is attached to an ImGui button press.

The issue I am having is that it seems that the Dannet command is coming in after the tank command, and is resetting the tank to assist mode. I tried inserting an 'mq.delay()' but that did nothing (literally, no matter what delay I use it does not delay - not sure mq.delay() works in the ImGui handler?).

I have had other cases of this happening, where Dannet commands occur in the opposite order from which they are sent (handled these using /multiline). But I would really like to know what is going on here. Alternatively, how would I wait for the Dannet command(s) to complete?
 
In ImGui there is no delay, but you can parcel off tasks to other routines that will delay.
 
In ImGui there is no delay, but you can parcel off tasks to other routines that will delay.
I guess sorta helpful. How about we assume I am an idiot and would actually like to know how to do it?

I am not familiar with the threading model for Lua (if there is one), so not sure what parceling off a task would be. If the ImGui handler is running, and I want to do something like this, how?
 
I guess sorta helpful. How about we assume I am an idiot and would actually like to know how to do it?

I am not familiar with the threading model for Lua (if there is one), so not sure what parceling off a task would be. If the ImGui handler is running, and I want to do something like this, how?
Code:
require 'ImGui'
local lib = require ('actions')
local action = 0

if ImGui.Button("pressed") then
action = 1
end

-- at the bottom
while GUI do

if action  == 1 then
lib.actions()
action = 0
end

a separate file named

actions.Lua or whatever you want to call it

local actions = {}

-- code here

return actions

best to look here:


I am sure there are other ways to do it, but most of my code I always offload and make everything modular as possible.
 
Last edited:
Code:
require 'ImGui'
local actions = require ('actions')
local action = 0

if ImGui.Button("pressed") then
action = 1
end

-- at the bottom
while GUI do

if action  == 1 then
lib.actions()
action = 0
end

a separate file named

actions.lua or whatever you want to call it

local actions = {}

-- code here

return actions

best to look here:

Thanks. I was hoping it wouldn't come to that. But at the same time, not sure how it would be avoided.

So basically, view the app as a single thread with ImGui being an ISR. Defer any real processing from the ISR to the main thread through some sort of job queue. And here I thought my days of programming super-loops were behind me.

You mentioned an actions library. Does this implement some sort of job queue functionality? I am envisioning some sort of queue that would store a function and some set of parameters so that I could add generic jobs from the ImGui handler. Completely new to Lua, so while it will be interesting to learn how, I would also love to see an example. I will start looking through the Lua's on the site, but if you know of any that do this I'd appreciate a tip.

Edit: OK, have the job queue thing mostly sorted. Made a basic FIFO queue and can add tables to it where the first element is the function, and additional elements are arguments. I think this can be made to work. My next open question is data integrity. This queue will be shared between the main loop and the ImGui callback. In this case I may be able to make the queue safe if the main loop only pops and ImGui pushes. But is there a more general mechanism to prevent the ImGui handler from interrupting the main loop during a critical section? (I suppose I could just use a flag to prevent the ImGui handler from doing anything on its tick. The main loop can't interrupt the handler. Will have to look into it.).
 
Last edited:
Question - How to sequence commands...

Users who are viewing this thread

Back
Top
Cart