Reply
Thread Tools Display Modes
Unread 01-29-12, 04:43 PM   #1
algritz
Claw of Regulos
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 11
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
Unfortunately when I get in this "loop" the CPU time gets eaten entirely and crashes the Game client.

My question is how do you get to wait for the Queue without crashing the game client?
algritz is offline   Reply With Quote
Unread 01-29-12, 09:21 PM   #2
Myrroddin
Endless Captain
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 50
Answered here.
Myrroddin is offline   Reply With Quote
Unread 01-30-12, 12:26 PM   #3
algritz
Claw of Regulos
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 11
Quote:
Originally Posted by Myrroddin View Post
Answered here.
Saw the reply, thanks !
algritz is offline   Reply With Quote
Unread 02-10-12, 12:21 PM   #4
Zoc
Bomani Harbinger
AddOn Author - Click to view addons
Join Date: Feb 2012
Posts: 6
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
I'm not able to understand the concept post. I can't find anything related to "Event.Queue.Status", which appears here:
Code:
table.insert(Event.Queue.Status, {QueueStatus, "MyAddon", "Queue Status"})
Anytime I try to run DoCommands(), it never goes past the first step.

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!
Zoc is offline   Reply With Quote
Unread 02-10-12, 02:27 PM   #5
algritz
Claw of Regulos
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 11
Quote:
Originally Posted by Zoc View Post
I'm not able to understand the concept post. I can't find anything related to "Event.Queue.Status", which appears here:
Code:
table.insert(Event.Queue.Status, {QueueStatus, "MyAddon", "Queue Status"})
Anytime I try to run DoCommands(), it never goes past the first step.

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!
Look at this thread, it helped me a LOT.

http://forums.riftgame.com/beta-addo...low-error.html

I ended up combining both a "Queue" and a "thread" manager.
algritz is offline   Reply With Quote
Unread 02-11-12, 03:51 AM   #6
Zoc
Bomani Harbinger
AddOn Author - Click to view addons
Join Date: Feb 2012
Posts: 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
Zoc is offline   Reply With Quote
Unread 02-12-12, 07:08 AM   #7
algritz
Claw of Regulos
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 11
Quote:
Originally Posted by Zoc View Post
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
Glad I could help !

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
algritz is offline   Reply With Quote
Unread 02-12-12, 12:41 PM   #8
Zoc
Bomani Harbinger
AddOn Author - Click to view addons
Join Date: Feb 2012
Posts: 6
Talking

Quote:
Originally Posted by algritz View Post
Glad I could help !

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
Thanks!

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
Zoc is offline   Reply With Quote
Unread 02-13-12, 05:36 AM   #9
algritz
Claw of Regulos
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 11
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
Re-reading this have me wondering though. "if not QueueStatus() then", I wonder if I should just call the queuestatus variable instead.

Last edited by algritz : 02-13-12 at 02:45 PM.
algritz is offline   Reply With Quote
Unread 02-13-12, 12:44 PM   #10
Zoc
Bomani Harbinger
AddOn Author - Click to view addons
Join Date: Feb 2012
Posts: 6
Arrow

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
Zoc is offline   Reply With Quote
Unread 02-13-12, 02:23 PM   #11
algritz
Claw of Regulos
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 11
Quote:
Originally Posted by Zoc View Post
How do you handle the "pause" command ? I don't see a registered coroutine.
My bad, I forgot to include it in my code, I'll update my previous comment.


Quote:
Also, I don't see QueueStatus() returning a value, and queueStatus var is never read on mailOpen(k).
This is due to the lack of clarity of my own code (shame on me) I end up just checking the value of the "global" queueStatus (it is defined as a local, but since it is done at the root level of my add-on its ends up being accessible everywhere)

Quote:
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
I totally agree, I just realized how much my code is a mess :P
algritz is offline   Reply With Quote
Reply

Go BackRiftui » AddOns, Layouts and Macros » Help/Support » How do you "wait" without crashing the game client.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off