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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1324 Part V ■ Appendixesthe basic structure <strong>of</strong> the phrase in the target language but not how some particularterm translates. You can find GlobalStrings.lua from other locales onsome addon sites <strong>and</strong> compare the phrases to come up with the missing term.Avoid Deprecated SystemsThe <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong> UI code has gone through many evolutionary <strong>and</strong>revolutionary changes as new needs <strong>for</strong> the game <strong>and</strong> from the addon communityhave come to light. New systems are constantly being added <strong>and</strong>tweaked to take better advantage <strong>of</strong> Lua design patterns, improve efficiency,<strong>and</strong> implement new game features.Un<strong>for</strong>tunately, the time invested in the older systems is significant enoughthat many <strong>of</strong> them are still around in some <strong>for</strong>m or another. Through thepatch cycle, though, the default UI is being slowly reworked to use the newermethods <strong>and</strong>, at some point in time, the old ways may no longer be supported.Throughout this book we have purposefully omitted coverage <strong>of</strong> these pastpractices. If you use the code <strong>for</strong> the default UI or other addons as researchmaterial <strong>for</strong> your own addon, translate any usage <strong>of</strong> the constructs discussedin the following sections into the newer method.NOTE Rather than listing all deprecated systems in this section, specific events,APIs, <strong>and</strong> so <strong>for</strong>th that should no longer be used are marked as deprecated in theirreference entries (see Part IV).Global Widget H<strong>and</strong>ler ArgumentsThe widget h<strong>and</strong>ler system you saw in Chapter 12 is new as <strong>of</strong> patch 2.0.Instead <strong>of</strong> calling your h<strong>and</strong>ler with a self parameter <strong>and</strong> other related data(button <strong>for</strong> OnClick, event <strong>and</strong> ... <strong>for</strong> OnEvent, <strong>and</strong> so on), the old systemused a global variable called this <strong>and</strong> several global argument variables (arg1,arg2,<strong>and</strong>soon).There were a few problems with this approach. Using global variables <strong>for</strong> aparameterized system does not make much sense conceptually, not to mentiontheir impact on per<strong>for</strong>mance. Also, the generic argn variables go against thevery first pointer in this appendix. The only way <strong>for</strong> you to know the meaning<strong>of</strong> the argument when reading old code is to look at a reference <strong>for</strong> the givenh<strong>and</strong>ler or hope you can infer its meaning from what the code does with it.Following are two somewhat useless functions to illustrate the difference.If you use SetScript to assign them to an OnHyperlinkClick script, they willfunction identically.function MyAddon_OnHyperlinkClick()if arg3 == “LeftButton“ thenthis.link = arg1print(“You clicked on “..arg2)endend

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

Saved successfully!

Ooh no, something went wrong!