Riftui

Riftui (https://www.riftui.com/forums/index.php)
-   Help/Support (https://www.riftui.com/forums/forumdisplay.php?f=3)
-   -   How do you "wait" without crashing the game client. (https://www.riftui.com/forums/showthread.php?t=212)

algritz 01-29-12 04:43 PM

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?

Myrroddin 01-29-12 09:21 PM

Answered here.

algritz 01-30-12 12:26 PM

Quote:

Originally Posted by Myrroddin (Post 740)
Answered here.

Saw the reply, thanks !

Zoc 02-10-12 12:21 PM

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! :)

algritz 02-10-12 02:27 PM

Quote:

Originally Posted by Zoc (Post 772)
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.

Zoc 02-11-12 03:51 AM

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 :D

algritz 02-12-12 07:08 AM

Quote:

Originally Posted by Zoc (Post 775)
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 :D

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 :o

Zoc 02-12-12 12:41 PM

Quote:

Originally Posted by algritz (Post 779)
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 :o

Thanks! :D

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 :D

algritz 02-13-12 05:36 AM

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.

Zoc 02-13-12 12:44 PM

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 :)

algritz 02-13-12 02:23 PM

Quote:

Originally Posted by Zoc (Post 786)
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


All times are GMT -6. The time now is 04:37 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2022 MMOUI