+ Reply to Thread
Results 1 to 5 of 5

Thread: When is player unit available ?

  1. #1
    Plane Touched
    Join Date
    Mar 2012
    Posts
    247

    Default When is player unit available ?

    Hi,

    I'm new to the API and I have a question.

    How do you wait for the player unit to be ready. When the addon is loaded I don't have access to all the details of my player using Inspect.Unit.Detail("player").

    I can use the event Event.Unit.Available and check if the unit is the player, but it seems overkill to listen to that event just to use it once.

    Thanks

    EDIT : Just realized I could do a table.remove to stop listening to this event, but anyway tell me if it's the way to go ^^
    Last edited by kode9; 05-15-2012 at 08:25 AM.

  2. #2
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default

    Quote Originally Posted by kode9 View Post
    Hi,

    I'm new to the API and I have a question.

    How do you wait for the player unit to be ready. When the addon is loaded I don't have access to all the details of my player using Inspect.Unit.Detail("player").

    I can use the event Event.Unit.Available and check if the unit is the player, but it seems overkill to listen to that event just to use it once.

    Thanks

    EDIT : Just realized I could do a table.remove to stop listening to this event, but anyway tell me if it's the way to go ^^
    Yep, that's the way to go. I also wouldn't do table.remove, as that seems to break events across all addons. Just drop out of your handler straight away. It's also worth noting that the player can go unavailable as well (when zoning).

    Gadgets: Unit Frames and Other Stuff for RIFT

  3. #3
    Champion
    Join Date
    Jun 2011
    Posts
    561

    Default

    DO NOT DO TABLE.REMOVE !


    Doing this will break any other addon relying on that event!

    Cheers
    N.

  4. #4
    Plane Touched
    Join Date
    Mar 2012
    Posts
    247

    Default

    Thanks for the answers. The only thing that bothered me is that the event handler will be called every time the mouse go over a NPC (thus performing useless operations).

    But I guess it's not much of a big deal, and I'll probably need the event for other stuff anyway

  5. #5
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default

    Yep, I really wouldn't worry about it. It does jar a little when you're trying to write efficient code and you have to leave these things lying around

    This is ripped out of my addon, and is probably doing the same thing you're doing as well. Basically, it waits for the first unit to become available before initializing things. In my addon, a module can register an initializer when it is loaded, and this is then called back by the main module once it knows everything is loaded and ready.

    Code:
    local initializersRun = false
    
    local function OnUnitAvailable(units)
        if initializersRun then return end
        ... do stuff ...
        initializersRun = true
    end

    Gadgets: Unit Frames and Other Stuff for RIFT

+ 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