Reply
 
Thread Tools Display Modes
Unread 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
Macro-Wow is offline   Reply With Quote
Unread 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,192
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.
Dridzt is offline   Reply With Quote
Unread 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,192
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.
Dridzt is offline   Reply With Quote
Unread 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
Macro-Wow is offline   Reply With Quote
Unread 09-24-12, 03:16 PM   #5
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,576
%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".
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 09-24-12 at 03:19 PM.
Phanx is offline   Reply With Quote
Unread 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: 1,062
%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.
__________________
"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.
SDPhantom is offline   Reply With Quote
Unread 09-24-12, 03:25 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 9,688
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

Seerah is offline   Reply With Quote
Unread 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,192
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
Dridzt is offline   Reply With Quote
Reply

Go BackWoWInterface » 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