12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 18 ■ Responding to Graphic Updates with OnUpdate 355Figure 18-3: Free slot warning displayed in the RaidWarningFrameThere is a problem with this code that can be seen when using the EquipmentManager. The Equipment Manager is a system that allows you to save multiplegear sets, <strong>and</strong> switch them with a single button. That’s accomplished by rapidlyequipping (or un-equipping) items as necessary. The Equipment Manager isdisabled by default, but can be enabled on the Controls menu under InterfaceOptions.Depending on your latency to the server, the number <strong>of</strong> items you areequipping or un-equipping, <strong>and</strong> the number <strong>of</strong> slots you have free in yourbags, you may find this code warning you multiple times <strong>for</strong> the sameequipment change. That is because the BAG_UPDATE event is firing more thanonce in a short period <strong>of</strong> time. You can use an OnUpdate to help fix this problem,as you see in the next section.Grouping Multiple EventsThe original code can be altered to not immediately trigger the bag scan, butinstead to schedule it <strong>for</strong> some time in the future using an OnUpdate. Edit thecode as follows, noting the highlighted differences from the previous version:if not BagWatchFrame thenBagWatchFrame = CreateFrame(“Frame“)endBagWatchFrame.THROTTLE = 0.5BagWatchFrame.WARN_LEVEL = 0.2BagWatchFrame.message = “You are running low on bag space!“BagWatchFrame.fullMessage = “Your bags are full!“local function bagWatch_ScanBags(frame)local maxSlots, freeSlots = 0, 0<strong>for</strong> idx = 0, 4 domaxSlots = maxSlots + GetContainerNumSlots(idx)freeSlots = freeSlots + GetContainerNumFreeSlots(idx)endlocal percFree = freeSlots / maxSlotslocal msgif percFree == frame.percFree then

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!