I made a very simple addon (almost as simple as “hello world”) that uses C_MountJournal.GetMountFromItem().
When I load the game, it either prints out the correct value of 2261 or the call doesn’t work and it prints out nil.
It doesn’t matter if I load the game or use /reload - it’s about 50/50 for a 2261 result or a nil result. Therefore, the issue isn’t directly related to initial game loading.
ahw.toc:
## Interface: 110005
## Title: AHW
## Author: Bitcaster
## Notes: Test Mount Code
## Version: 1.0.0
ahw.lua
ahw.lua:
print(C_MountJournal.GetMountFromItem(228760))
If this call is not reliable 100% of the time, then I can’t use it for what I have planned.
Items need to be retrieved from the server and cached before you can get information from them. Try:
local item = Item:CreateFromItemID(228760)
item:ContinueOnItemLoad(function()
print("Mount ID:", C_MountJournal.GetMountFromItem(228760))
end)
2 Likes
Thanks - that worked!
Since the argument to ContinueOnItemLoad() is a lambda function, is there a way I could pass the item ID (228760) to the function?
Eventually I’ll want the item ID to be a variable, so it won’t be hardcoded.
Would something like this be correct-ish?
local itemID = 228760
local item = Item:CreateFromItemID(itemID)
item:ContinueOnItemLoad(function(itemID)
print("Mount ID:", C_MountJournal.GetMountFromItem(itemID))
end)
Depending on need, you could do something like:
local itemID
local function PrintMountID()
print("Mount ID:", C_MountJournal.GetMountFromItem(itemID))
end
local function DoSomethingWithMount(itemid, action)
itemID = itemid
local item = Item:CreateFromItemID(itemID)
item:ContinueOnItemLoad(action)
end
DoSomethingWithMount(228760, PrintMountID)
1 Like
Thanks Fizzlemizz - very VERY helpful!
Much appreciated!