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.

Appendix A ■ Best Practices 1325function MyAddon_OnHyperlinkClick(self, link, text, button)if button == “LeftButton“ thenself.link = linkprint(“You clicked on “..text)endendAs you can see, this corresponds to self, arg1 corresponds to link, arg2corresponds to text, <strong>and</strong>arg3 corresponds to button. With the exception <strong>of</strong>the OnEvent h<strong>and</strong>ler, this <strong>and</strong> arg1-argn will always match the parameter list<strong>of</strong> the given h<strong>and</strong>ler. In this way, you can use the widget h<strong>and</strong>ler referencein Chapter 31 to determine the meanings <strong>of</strong> the global arguments in anylegacy code. The only difference with OnEvent is that event always had itsown global. arg1-argn, in this case, correspond to the parameters passedthrough ....bag <strong>and</strong> slot Attributes on item Type Action ButtonsAnother change in 2.1 is the simplification <strong>of</strong> secure action buttons with a“type“ attribute <strong>of</strong> “item“. Previously, the “item“ attribute could only beused to activate an item by name. To use an item in your inventory wouldrequire a “slot“ attribute; to use an item in your bags required “bag“ <strong>and</strong>“slot“ attributes. Now the “item“ attribute works the same way as the /usemacro comm<strong>and</strong>. It accepts an item name, item ID (in the <strong>for</strong>m “item:12345“),slot number, or bag <strong>and</strong> slot numbers separated by a space (<strong>for</strong> example,“3 12“).Again, <strong>for</strong> backward compatibility, the “bag“ <strong>and</strong> “slot“ attributes arestill supported. However, you should no longer use them; as a comment inFrameXML\SecureTemplates.lua says, ‘‘Backward compatibility code, deprecatedbut still h<strong>and</strong>led <strong>for</strong> now.’’ [Emphasis mine.]Avoiding Common MistakesAddon authors can make dozens <strong>of</strong> common mistakes as they develop theiraddons. Many <strong>of</strong> them have been covered throughout the book, but thefollowing deserve to be mentioned here, as well.Adding Files While <strong>WoW</strong> Is RunningWhen <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong> loads, it scans the file system <strong>and</strong> builds a table <strong>of</strong>files that can be loaded during that session. If you add files while the game isopen, they won’t be part <strong>of</strong> that table <strong>and</strong> cannot be loaded or recognized bythe game. A related common mistake is adding a new file to your addon <strong>and</strong>the Table <strong>of</strong> Contents file without fully exiting the game.If you add files to the file system, make sure that you fully exit <strong>and</strong> restartthe game so that the changes will be fully registered.

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

Saved successfully!

Ooh no, something went wrong!