Thread Tools Display Modes
09-24-12, 12:51 PM   #1
Macro-Wow
A Deviate Faerie Dragon
Join Date: Sep 2012
Posts: 18
Lua macro tutorial

Wrote my first Lua scripting guide for making a simple Wow macro, what do you think?

How to make a Lua script Wow macro
__________________
My Wow macros website:
Macro-Wow.com - handpicked Wow macros
Share your macros!

Interests include web dev, design and gaming
  Reply With Quote
09-24-12, 01:20 PM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Looks good

A couple things.
a and b are global, that can be troublesome especially if someone (or even Blizz with recent _ history fresh) forgets a global themselves (eg r, g, b ?)

Whitespace is good for explaining things but there should be a note that in the final macro everything that can be removed is removed so you can fit more stuff in the 255 char limit.
';' is completely useless in any case.

I don't think your final macro fits in 255 chars as it is.

Last edited by Dridzt : 09-24-12 at 01:22 PM.
  Reply With Quote
09-24-12, 01:28 PM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Code:
/run local a,b=GetNumCompletedAchievements()print(('%s/%s achievements'):format(a,b))print(('that is %d%%'):format(b/a*100))
This should do somewhat the same thing and is already 248 characters.
  Reply With Quote
09-24-12, 03:08 PM   #4
Macro-Wow
A Deviate Faerie Dragon
Join Date: Sep 2012
Posts: 18
Thanks! I intentionally left out the rounding so not to confuse them, I used math.floor - wasn't sure what the standard was, format looks awesome. Didn't think about the local declaration. Where does that s and d get defined in your print statements - will it just take whatever you put in there?
__________________
My Wow macros website:
Macro-Wow.com - handpicked Wow macros
Share your macros!

Interests include web dev, design and gaming
  Reply With Quote
09-24-12, 03:16 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
%s and %d are standard Lua string formatting tokens.

http://pgl.yoyo.org/luai/i/string.format
http://www.wowpedia.org/API_format

%s means "convert the provided value into a string and insert it here". string.format("Hello, %s!", "world") is the same as "Hello, " .. "world" .. "!" but more localization-friendly, more flexible, and more powerful.

%d means "round the provided number into the nearest integer and insert it here".
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 09-24-12 at 03:19 PM.
  Reply With Quote
09-24-12, 03:20 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
%s and %d are format identifiers used by string.format(). They practicly take the arguments passed and format them according to how they're configured in the place those identifiers appear in the string. This function is also known as the global, format().

See the C documentation of sprintf() for more information on format identifiers and their configurations.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-24-12 at 03:23 PM.
  Reply With Quote
09-24-12, 03:25 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
http://www.lua.org/manual/5.1/manual...-string.format
http://lua-users.org/wiki/StringLibraryTutorial


What are you using to count your characters, Dridzt? MacroWoW's final macro fits in 255, and yours is only 124 (according to http://www.macroexplain.com/)

Though you could just do...
Code:
/run local a,b=GetNumCompletedAchievements()print(a.."/"..b.."achievements")print("that is".. b/a*100.."%")
to save even more space (107 chars). The performance lost is very negligible between the two versions.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-24-12, 03:33 PM   #8
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Originally Posted by Seerah View Post
<snip>
What are you using to count your characters, Dridzt? MacroWoW's final macro fits in 255, and yours is only 124 (according to http://www.macroexplain.com/)
UltraEdit's bytecount, haha, should probably be looking at column count for utf8 files (my default format) it's half the length I was thinking sorry about the confusion
  Reply With Quote
09-24-12, 06:23 PM   #9
Macro-Wow
A Deviate Faerie Dragon
Join Date: Sep 2012
Posts: 18
Lua is sort of elegant, I like it so far! I intentionally put the if statement in there for the tutorial, not cause we needed it. Next one I do will revolve around the for loop, just for the guide's sake.

Should be some fun challenges with the new expansion - I don't think I can stay up tonight tho with work
__________________
My Wow macros website:
Macro-Wow.com - handpicked Wow macros
Share your macros!

Interests include web dev, design and gaming
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » Macro Help » Lua macro tutorial

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off