WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   When GetInventoryItemLink is ready to use? (https://www.wowinterface.com/forums/showthread.php?t=52497)

alikim 07-12-15 05:22 AM

When GetInventoryItemLink is ready to use?
 
I'm trying to get information about equipped items via GameTooltip, so I have this code in the event handler frame (I know I should use my own scan tooltip for this, and I do, but for this it doesn't matter):

Code:

if event == "PLAYER_ENTERING_WORLD" then
        local iLink = GetInventoryItemLink("player", 16)
        print(iLink, gsub(iLink, "\124", "\124\124"))
        GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
        GameTooltip:SetHyperlink(iLink)
        GameTooltip:Show()
        print(GameTooltip:NumLines())
        return
end

When I print iLink - it's missing item color, it's always "ffffff" and the name, it's empty "[]". GameTooltip come up saying "Requires item information", so I get NumLines = 1 and then quickly updates itself with the right item info.

If I execute the same code 1 sec after PLAYER_ENTERING_WORLD it works fine, iLink is not broken.

Is there any event that I can use to make sure at this time GetInventoryItemLink will work?

I tried UNIT_INVENTORY_CHANGED but it fires 112 times in a row after each PLAYER_ENTERING_WORLD so it's not really helpful.

Thanks,

Jarod24 07-12-15 06:54 AM

If i understand correctly the scenario you are describing, then the problem is that your code is running -before- everything in the game is finished loading properly.

-Do not run the code until after PLAYER_ENTERING_WORLD has fired.
-Possibly run it 1 second after the event has triggered. Take a look at the C_Timer.After() function to make a callback function to yourself.

Does the code have to be executed the instant the user is logging in/reloading?
Maybe use some other event or function that you can hook into (player moved, character tab opened).


You mention UNIT_INVENTORY_CHANGED firing 112 times; You could always change it so that your code only runs once and ignores the other 111 times it's fired:
-unregister from the event after the first time its triggered
-use a boolean to stop the code executing more than once (booFirstTime = false/true)

alikim 07-12-15 08:33 AM

Quote:

Originally Posted by Jarod24 (Post 309747)
If i understand correctly the scenario you are describing, then the problem is that your code is running -before- everything in the game is finished loading properly.

-Do not run the code until after PLAYER_ENTERING_WORLD has fired.
-Possibly run it 1 second after the event has triggered. Take a look at the C_Timer.After() function to make a callback function to yourself.

Does the code have to be executed the instant the user is logging in/reloading?
Maybe use some other event or function that you can hook into (player moved, character tab opened).


You mention UNIT_INVENTORY_CHANGED firing 112 times; You could always change it so that your code only runs once and ignores the other 111 times it's fired:
-unregister from the event after the first time its triggered
-use a boolean to stop the code executing more than once (booFirstTime = false/true)

As you can see from the code above I run it after PLAYER_ENTERING_WORLD fired and GetInventoryItemLink() is not working correctly at this point, that's the problem.

I can create a delay but it's not a good practice, how long this delay needs to be? 1 sec is enough for me, I don't know if it's enough for other people who have slower computers or whatever else is different.

If UNIT_INVENTORY_CHANGED fired once and after that GetInventoryItemLink() would work that'll be fine but it fires 112 times, I'm not sure if this magic number is the same for all people, so I can't relay on waiting till it fires 112 times and then try GetInventoryItemLink(), not to mention I've no idea what's being updated 112 times, there are only 18 slots in inventory for equipping/unequipping items.

I'm making an inventory tooltip that I want to be on the screen right after you enter the world, again not after some arbitrary delay hoping it's gonna be enough (or making it ridiculously long like 10 sec) but after a certain point(event) that insures evrything has been loaded and GetInventoryItemLink() works.

I was sure that PLAYER_ENTERING_WORLD is it but it's not.

Everything works if you relog or update UI, this problem only occurs when you start the game from the launcher for the first time.

semlar 07-12-15 08:50 AM

Item information has to be requested from the server; if GetItemInfo returns nil, then GET_ITEM_INFO_RECEIVED will fire with the item ID when the info becomes available.

alikim 07-12-15 10:54 AM

That helped, thank you!


All times are GMT -6. The time now is 06:20 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI