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.

Chapter 17 ■ <strong>Creating</strong> Slash Comm<strong>and</strong>s 347Now all you need to do is tie it together with a slash comm<strong>and</strong>:SLASH_COMMANDTABLE1 = “/comm<strong>and</strong>table“SLASH_COMMANDTABLE2 = “/cmdtbl“SlashCmdList[“COMMANDTABLE“] = function(message)DispatchComm<strong>and</strong>(message, testComm<strong>and</strong>Table)endAnd voila! Twenty-one lines <strong>of</strong> code later <strong>and</strong> you have a powerful slashcomm<strong>and</strong> h<strong>and</strong>ler that uses a simple table <strong>for</strong> configuration. Here is somesample output:/cmdtbl gui showShowing/comm<strong>and</strong>table dataData comm<strong>and</strong>s: load , save , reset/cmdtbl GUI Width 13Setting width to 13SummaryIn this chapter you learned the basics <strong>of</strong> slash comm<strong>and</strong>s <strong>and</strong> how to geta barebones comm<strong>and</strong> up <strong>and</strong> running. You also examined a set <strong>of</strong> tips<strong>and</strong> tricks you can use to make your code more flexible <strong>and</strong> cleaner. Slashcomm<strong>and</strong>s aren’t flashy, <strong>and</strong> in some circles they get a bad rap, but they’repowerful, flexible, <strong>and</strong>, if implemented correctly, elegant. One very powerfulaspect <strong>of</strong> slash comm<strong>and</strong>s versus graphical configuration interfaces is thatslash comm<strong>and</strong>s can be used in macros, allowing users to change their settingson-the-fly using buttons on their action bars.The CodeSlashCalclocal NUMBER_PATTERN = “ ˆ %s*([+-]?%d*%.?%d+)“local OPERATOR_PATTERN = “ ˆ %s*(.)“local END_PATTERN = “ ˆ %s*$“local NUMBER_ERROR = “No valid number at position %d“local OPERATOR_ERROR = “Unrecognized operator at position %d: '%s'“local errorState = false

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

Saved successfully!

Ooh no, something went wrong!