It might be because it is processing things a bit too soon.
You could see if using the MERCHANT_UPDATE event ( at least the first time around ) will be the best time to do any semi automatic transactions.
Looking at the MerchantFrame Blizzard code (
https://github.com/Gethe/wow-ui-sour...chantFrame.lua ) The updating of the merchant frame doesn't occur until the end of the Merchant_Show function. So it is possible that the following is happening.
Lua Code:
function MerchantFrame_MerchantShow()
ShowUIPanel(MerchantFrame);
>>>> MERCHANT_SHOW triggers here perhaps
if ( not MerchantFrame:IsShown() ) then
CloseMerchant();
return;
end
MerchantFrame.page = 1;
MerchantFrame_UpdateCurrencies();
MerchantFrame_Update();
>>>> MERCHANT_UPDATE triggers here perhaps
end
Depending on how often MERCHANT_UPDATE triggers, you might need to UnRegister it when it first triggers and have registering it happen when the MERCHANT_SHOW event triggers.
For example:
Lua Code:
local addonName, addon = ...
-- Whatever Data or Functionality that needs to be available before
-- It is accessed in AutoPurchaseSelectedItems function
-- Either in this file or in a file listed earlier in the toc file
local function AutoPurchaseSelectedItems()
-- Whatever Buying from Merchant processing you wanted to do
end
local function OnEvent(self,event,...)
if event == "MERCHANT_SHOW" then
self:RegisterEvent("MERCHANT_UPDATE")
elseif event == "MERCHANT_UPDATE" then
self:UnregisterEvent(event)
AutoPurchaseSelectedItems()
end
end
local eventWatcher = CreateFrame("Frame")
eventWatcher:RegisterEvent("MERCHANT_SHOW")
eventWatcher:SetScript("OnEvent",OnEvent)
-- OR --
If that doesn't work. You could try hooking into the MerchantFrame_MerchantShow function to add your functionality in place.
For example:
Lua Code:
local addonName, addon = ...
-- Whatever Data or Functionality that needs to be available before
-- It is accessed in AutoPurchaseSelectedItems function
-- Either in this file or in a file listed earlier in the toc file
local function AutoPurchaseSelectedItems()
-- Whatever Buying from Merchant processing you wanted to do
end
hooksecurefunc("MerchantFrame_MerchantShow", AutoPurchaseSelectedItems)
-- What this does is execute the Blizzard MerchantShow function and immediately execute your function. You won't have access to any variables inside the Blizzard function but it might allow you to access the Merchant in the same way you are doing already, just after it does that initial update.