Chapter 22: Page 420 - 'Creating Faux Scroll Frames'

The API to retrieve macro icons has changed slightly with the release of the 4.3 patch for World of Warcraft. There are several changes that are required in order to fix the MacroIconTest addon. You can download An updated version of the addon code.

At the bottom of page 120, we start adding code to MacroIconTest.lua. Instead of adding the function given in the book, add the following code instead:

 MacroIconTest_Icons = {}

 function MacroIconTest_GetIcons()
   GetMacroIcons(MacroIconTest_Icons)
   GetMacroItemIcons(MacroIconTest_Icons)
 end

Here we declare a new global table that is used to store the icon information. We then create a function we can call to fill in the icon table (it will be triggered by an event after the game has loaded).

Then add the function to update the displayed icons:

  function MacroIconTest_UpdateIcons(startIcon)
    local name = "MacroIconTestIcon"

    for i=1,6 do
      local texture = MacroIconTest_Icons[startIcon + (i - 1)]
      local button = _G[name .. i]
      button:SetNormalTexture("INTERFACE\\ICONS\\" .. texture)
    end
  end

The filenames provided by the GetMacroIcons function don't include the beginning portion, so we add that here and set the textures directly.

In the widget handler script for </OnEvent> added on page 421, use the following code instead of the code printed in the book:

         <OnEvent>
             if event == "PLAYER_LOGIN" then
                 MacroIconTest_GetIcons()
                 MacroIconTest_UpdateIcons(1)
             end
         </OnEvent>

When we add the scroll bars we'll need to add a bit of code to the initialization logic. Once you've added the XML on page 422, add the following code to the end of MacroIconTest_GetIcons:

 local max = #MacroIconTest_Icons
 local slider = MacroIconTest_HSlider
 slider:SetMinMaxValues(1, max - 5)
 slider:SetValueStep(1.0)
 slider:SetValue(1)

This replaces the code in the <OnLoad> handler at the bottom of 422 and the top of 423 (simply remove that event handler from that block of code).

Finally, there's a small change required in the section Scrolling with the Mouse Wheel. We can't use the API to get the number of macros, so we use the length operator on the icon table itself, so replace:

 if (delta < 0) and (current < GetNumMacroIcons()) then

with

 if (delta < 0) and (current < #MacroIconTest_Icons) then

If you have any issues getting it working, please feel free to post on the forums.