+ Reply to Thread
Results 1 to 8 of 8

Thread: How do you "wait" without crashing the game client.

  1. #1
    Rift Disciple
    Join Date
    Mar 2011
    Posts
    130

    Default 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?
    Last edited by Frostshizzle; 01-29-2012 at 02:37 PM.

  2. #2
    RIFT Community Ambassador the_real_seebs's Avatar
    Join Date
    Jan 2011
    Posts
    16,859

    Default

    You set up an event handler that will fire every so often (say, once a frame) and check for whatever you're looking for.

    There is only one thread of execution. If you sit there checking for the queue to be done, then NOTHING else happens. Including any processing of the queue. Or rendering. The entire game is waiting for your code to finish, which it doesn't.

    Have a look, if you want, at LibPerfORate, which has code for benchmarking something by running it in the background so it doesn't interfere significantly with gameplay.
    You can play WoW in any MMO. You don't have to play WoW in RIFT. Oh, and no, RIFT is not a WoW clone. Not having fun any more? Learn to play, noob! I don't speak for Riftui, but I moderate stuff there. Just came back? Welcome back! Here's what's changed. (Updated for 2.5!)

  3. #3
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default

    Quote Originally Posted by Frostshizzle View Post
    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?
    Your code can be rewritten this way, if I understand.
    Code:
    local function wait_for_queue()
        -- get status
        local queue_is_not_ready = Inspect.Queue.Status("global")
        -- let's rewrite the next statement. first, you do not need "== true" because it is redundant
        -- second, let's use psuedocode
        while queue_is_not_ready do
            queue_is_not_ready = Inspect.Queue.Status("global")
            -- if var is true, loop
        end
    end
    The problem with this code is that it endlessly loops, locking the computer until it finally becomes false. Your code execution does not allow for anything else. What you want to do is register for Event.Queue.Status, do your Inspect.Queue.Status("global") in the event handler, return if the Inspector is true to immediately exit out, else process. The following is what you want instead.
    Code:
    local function QueueStatus()
        local queueStatus = Inspect.Queue.Status("global")
        if queueStatus then return end -- global queue is still backlogged, so exit out
        
        -- ok, global queue is empty
        command.blah -- fills queue, making queueStatus true, event function fires
        -- back to false, and event handler fires again, process next command
        command.blah2
        -- back to true, rinse, repeat
    end
    
    table.insert(Event.Queue.Status, {QueueStatus, "MyAddon", "Queue Status"})
    The advantage of doing it this way is the QueueStatus function will not be called endlessly, and only if the queue's status changes. Do all your command calls, one right after the other, where the comment says "do other stuff."
    Last edited by Lorandii; 01-29-2012 at 07:35 PM.

  4. #4
    Rift Disciple
    Join Date
    Mar 2011
    Posts
    130

    Default

    Thanks for your replies !

    I'll refactor my code in that sense.

  5. #5
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default fixed, I hope

    I just realized my code principle is correct, but the execution will never get to the second, third, etc commands. The following is better.
    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
    Last edited by Lorandii; 01-30-2012 at 02:40 PM. Reason: Typo

  6. #6
    Rift Disciple
    Join Date
    Mar 2011
    Posts
    130

    Default

    very appreciated !

  7. #7
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default

    There is an even better way, using a Do - end loop, with a break. Want it, or are you good now?

  8. #8
    Rift Disciple
    Join Date
    Mar 2011
    Posts
    130

    Default

    Quote Originally Posted by Lorandii View Post
    There is an even better way, using a Do - end loop, with a break. Want it, or are you good now?
    Seems to be working now, thanks !

    However I'm facing "Failed to take attachments" errors, despite the queue being available. I think this is a client related issue rather than a code issue though.

    I'm also facing something similar when trying to post items, "Error, please free up some space" and yet my bags were almost empty.

    https://www.youtube.com/watch?v=-m8E...w6aMbn-WHuxzpl
    Watch in 720p in order to see the error

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts