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.

CHAPTER17<strong>Creating</strong> Slash Comm<strong>and</strong>s<strong>World</strong> <strong>of</strong> <strong>Warcraft</strong> players interact daily with slash comm<strong>and</strong>s. Whether it’s/ignore Ikeelyou or a hasty /gquit after ninja looting Kael’thas on yourguild’s first takedown, you’re using slash comm<strong>and</strong>s.As an addon author, you’ll <strong>of</strong>ten find it easier or just plain useful to haveslash comm<strong>and</strong>s to either spur your addon to action or to enable configuration.Generally speaking, it’s much quicker to write out a quick slash comm<strong>and</strong>system than to have a fully functioning graphical configuration screen.<strong>Creating</strong> Basic Slash Comm<strong>and</strong>s<strong>WoW</strong> provides a fairly straight<strong>for</strong>ward way to implement slash comm<strong>and</strong>s.They require two basic components: a set <strong>of</strong> global variables <strong>for</strong> the comm<strong>and</strong>s<strong>and</strong> a h<strong>and</strong>ler function in a global table. Here is a quick example:SLASH_FANCYPRINT1 = “/fancyprint“SlashCmdList[“FANCYPRINT“] = function(msg)print(“|cff11ff11“ .. Printed:|r “ .. msg)endOnce you’ve run that code, type the following in the chat frame’s edit box:/fancyprint This is my first slash comm<strong>and</strong>!You should see a message printed to the chat frame that says, ‘‘This is myfirst slash comm<strong>and</strong>!’’, after a green heading that says ‘‘Printed’’.Now take a look at the process that made this possible. <strong>WoW</strong> stores all theslash comm<strong>and</strong> h<strong>and</strong>lers in a table called SlashCmdList. The table is indexed337

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

Saved successfully!

Ooh no, something went wrong!