Scrap API change
zgavin opened this issue · 3 comments
A new version of Scrap was released on 12/25/19 that changed the API exposed by the addon. The Scrap object itself is no longer a Button and is instead just a table. This means Scrap.HookScript no longer exists. The button itself is now accessed via Scrap.Merchant, but it is lazy loaded so AdiBags will need to wait for it to be created.
Quick and dirty change i made to to Junk.lua, starting on line 246:
local old = Scrap.NewModule
Scrap.NewModule = function( self, id, ... )
local result = old( self, id, ... )
if id == 'Merchant' then
result:HookScript('OnReceiveDrag', function()
if prefs.sources.Scrap then
wipe(cache)
addon:SendMessage("AdiBags_FiltersChanged")
end
end)
end
return result
end
I'm seeing this error in the classic release as well. Scrap update seems to have happened across both game versions.
Date: 2019-12-29 08:09:29
ID: 1
Error occured in: Global
Count: 1
Message: ..\AddOns\AdiBags\modules\Junk.lua line 244:
attempt to call method 'HookScript' (a nil value)
Debug:
AdiBags\modules\Junk.lua:244: in main chunk
A new version of Scrap was released on 12/25/19 that changed the API exposed by the addon. The Scrap object itself is no longer a Button and is instead just a table. This means Scrap.HookScript no longer exists. The button itself is now accessed via Scrap.Merchant, but it is lazy loaded so AdiBags will need to wait for it to be created.
Quick and dirty change i made to to Junk.lua, starting on line 246:
local old = Scrap.NewModule Scrap.NewModule = function( self, id, ... ) local result = old( self, id, ... ) if id == 'Merchant' then result:HookScript('OnReceiveDrag', function() if prefs.sources.Scrap then wipe(cache) addon:SendMessage("AdiBags_FiltersChanged") end end) end return result end
sorry I'm being dumb but my junk.lua file looks very different to yours at line 246
are you suggesting we add your code block at line 246 - within the if function that begins on line 239 "if Scrap and type(Scrap.IsJunk) == "function" then"
thanks
A new version of Scrap was released on 12/25/19 that changed the API exposed by the addon. The Scrap object itself is no longer a Button and is instead just a table. This means Scrap.HookScript no longer exists. The button itself is now accessed via Scrap.Merchant, but it is lazy loaded so AdiBags will need to wait for it to be created.
Quick and dirty change i made to to Junk.lua, starting on line 246:local old = Scrap.NewModule Scrap.NewModule = function( self, id, ... ) local result = old( self, id, ... ) if id == 'Merchant' then result:HookScript('OnReceiveDrag', function() if prefs.sources.Scrap then wipe(cache) addon:SendMessage("AdiBags_FiltersChanged") end end) end return result endsorry I'm being dumb but my junk.lua file looks very different to yours at line 246
are you suggesting we add your code block at line 246 - within the if function that begins on line 239 "if Scrap and type(Scrap.IsJunk) == "function" then"
thanks
Nope - you must replace the function. A better (complete) way to do this is currently pending a PR merge #422
This is what I did (keeping the old code around):
-- Scrap:HookScript('OnReceiveDrag', function()
-- if prefs.sources.Scrap then
-- wipe(cache)
-- addon:SendMessage("AdiBags_FiltersChanged")
-- end
-- end)
-- BEGIN SCRAP FIX --
local function updateScrap()
if prefs.sources.Scrap then
wipe(cache)
addon:SendMessage("AdiBags_FiltersChanged")
end
end
if Scrap.HookScript then
Scrap:HookScript('OnReceiveDrag', updateScrap)
end
if Scrap.Merchant and Scrap.Merchant.HookScript then
Scrap.Merchant:HookScript('OnReceiveDrag', updateScrap)
end
if Scrap.ToggleJunk then
_G.hooksecurefunc(Scrap, "ToggleJunk", updateScrap)
end
-- END SCRAP FIX --