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 |
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. |
Code:
/run local a,b=GetNumCompletedAchievements()print(('%s/%s achievements'):format(a,b))print(('that is %d%%'):format(b/a*100)) |
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?
|
%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". |
%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. |
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.."%") |
Quote:
|
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 :( |
All times are GMT -6. The time now is 06:51 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI