Thread Tools Display Modes
07-12-15, 05:22 AM   #1
alikim
A Fallenroot Satyr
Join Date: Jul 2015
Posts: 27
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,
  Reply With Quote
07-12-15, 06:54 AM   #2
Jarod24
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 66
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)
__________________
Author of IfThen, Links in Chat

Last edited by Jarod24 : 07-12-15 at 07:06 AM.
  Reply With Quote
07-12-15, 08:33 AM   #3
alikim
A Fallenroot Satyr
Join Date: Jul 2015
Posts: 27
Originally Posted by Jarod24 View Post
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.

Last edited by alikim : 07-12-15 at 08:50 AM.
  Reply With Quote
07-12-15, 08:50 AM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
  Reply With Quote
07-12-15, 10:54 AM   #5
alikim
A Fallenroot Satyr
Join Date: Jul 2015
Posts: 27
That helped, thank you!
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » When GetInventoryItemLink is ready to use?

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