Go to Page... |
Thread Tools | Display Modes |
01-29-12, 04:43 PM | #1 |
How do you "wait" without crashing the game client.
I want to process my mailbox, then take the attachments and finally delete the email.
Two of these actions interacts with the global command queue. If I want to make sure everything is processed in order, I need to be able to wait after the queue. As such I've created a small function that loops while the queue becomes available. Code:
local function wait_for_queue() local queue_is_not_ready = Inspect.Queue.Status("global") while queue_is_not_ready == true do queue_is_not_ready = Inspect.Queue.Status("global") end end My question is how do you get to wait for the Queue without crashing the game client? |
|
02-10-12, 12:21 PM | #4 |
I'm not able to post on Rift forums (Rift Lite, etc. - willing to change that very soon).
Code:
local queueStatus = false local function QueueStatus() queueStatus = Inspect.Queue.Status("global") if queueStatus then return end -- global queue is still backlogged, var is true so exit out queueStatus = false end table.insert(Event.Queue.Status, {QueueStatus, "MyAddon", "Queue Status"}) local commandOne = false local commandTwo = false local commandThree = false function MyAddon:DoCommands() if not commandOne and not queueStatus then command.blah1 commandOne = true elseif not commandTwo and not queueStatus then command.blah2 commandTwo = true elseif not commandThree and not queueStatus then command.blah3 commandThree = true end commandOne, commandTwo, commandThree = false, false, false end Code:
table.insert(Event.Queue.Status, {QueueStatus, "MyAddon", "Queue Status"}) What I'm willing to do is, wait until a Command.Item.Move() is complete, then run 2 functions. Ideas how I can do that ? Thanks in advance! |
|
02-10-12, 02:27 PM | #5 | |
Quote:
http://forums.riftgame.com/beta-addo...low-error.html I ended up combining both a "Queue" and a "thread" manager. |
||
02-11-12, 03:51 AM | #6 |
Thank you!
With the info in the post you provided me, I created the LibCoroutine. It's very early and the code can be considered Alpha quality. It's included with zBag (Alpha4), in case you want to take a look on how I implemented it. Suggestions / improvements are welcome |
|
02-12-12, 07:08 AM | #7 | |
Quote:
I'll have a look at your library. Not sure I'll implement it for my add-on since I've already done this part, but maybe for my next project |
||
02-12-12, 12:41 PM | #8 | |
Quote:
I've uploaded it here: http://www.riftui.com/downloads/info...Coroutine.html It doesn't support Queue, like you used on your project ( I still need to study that part ), but in case you need it in your next project and want to improve the library, you're more than welcome to do so |
||
02-13-12, 05:36 AM | #9 |
here's how I have combines both:
Code:
-- Coroutines management table local function SetupCoroutineTable() coroutine_table = { }; end -- adds a coroutine to the queue local function AddCoroutine(Item) table.insert(coroutine_table, Item); end -- remove a coroutine to the queue local function RemoveCoroutine(Index) table.remove(coroutine_table, Index); end -- resumes a coroutine while it is active local function ResumeCoroutine(Index) Item = coroutine_table[Index]; if coroutine.status(Item) ~= 'dead' then coroutine.resume(Item); end end -- loops through the coroutines lists and calls the resume handler local function ResumeAllCoroutines() -- make sure there is something to process if coroutine_table ~= {} then for Index,Item in ipairs(coroutine_table) do ResumeCoroutine(Index); end else return end end -- pause timer function Pause(seconds) local start = Inspect.Time.Frame() while start + seconds > Inspect.Time.Frame() do coroutine.yield() end end -- function that check for the global queue status local queueStatus = false local function QueueStatus() -- inspects the queue status queueStatus = Inspect.Queue.Status("global") if queueStatus then return end -- global queue is still backlogged, var is true so exit out queueStatus = false end -- small function that opens an email local function MailOpen(k) -- check if the queue is available before opening if not QueueStatus() then Command.Mail.Open(k) else Pause(0.2) MailOpen(k) end end -- function that parses each email and store it in a emprary database for further processing local function Mailboxparser() print("Starting to read emails") local status = Inspect.Interaction("mail") if status == true then -- get the list of email mailList = Inspect.Mail.List() -- checking how many email will be parsed (cannot use table.getn, since this table contains key/values => only way is to iterate throught the table) mail_number = 0 for k,v in pairs(mailList) do mail_number = mail_number + 1 end -- index that stores the nuber of processed emails processed_mail_count = 1 -- fetch through each emails for k, v in pairs(mailList) do -- if email hasn't been parsed previously if not setContains(mail_history, k) or mail_history == {} then -- open email to have access to details mailOpen(k) Pause(0.2) -- get details details = (Inspect.Mail.Detail(k)) -- table that will store the mail content mail_details = {} -- feeding the table table.insert(mail_details, details["from"]) table.insert(mail_details, details["subject"]) table.insert(mail_details, details["body"]) --table.insert(mail_details, os.date) -- table that will contain teh attachment list if there is any attachment_list = {} -- detecty if the is any attachment if tonumber(details["attachments"]) == nil and details["attachments"] ~= nil then -- add item ids in a table for ka, va in pairs(details["attachments"]) do table.insert(attachment_list, va) end end table.insert(mail_details, attachment_list) -- detect if mail is actually "read" (only way to declare the mail as processed) if details["body"] ~= nil then addToSet(mail_history, k, mail_details) processed_mail_count = processed_mail_count + 1 end -- check if we're done processing if mail_number == processed_mail_count then print("Email recording complete: " .. processed_mail_count .. " entries saved") RemoveCoroutine(parsing_coro) end end end end end local function Launch_mailboxparser() parsing_coro = coroutine.create(Mailboxparser) AddCoroutine(parsing_coro) end SetupCoroutineTable() table.insert(Event.Queue.Status, {QueueStatus, "aher", "Queue Status"}) table.insert(Event.System.Update.Begin, {function() ResumeAllCoroutines() end, "aher", "OnUpdate" }) launch_mailboxparser() -- just for the sake of calling the function Last edited by algritz : 02-13-12 at 02:45 PM. |
|
02-13-12, 12:44 PM | #10 |
How do you handle the "pause" command ? I don't see a registered coroutine.
Also, I don't see QueueStatus() returning a value, and queueStatus var is never read on mailOpen(k). May I give you a suggestion ? Always start functions with Capital letter and avoid naming variables with the same name as functions, just differing on letter capitalization |
|
02-13-12, 02:23 PM | #11 | |||
Quote:
Quote:
Quote:
|
||||
Riftui » AddOns, Layouts and Macros » Help/Support » How do you "wait" without crashing the game client. |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|