WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Macro Help (https://www.wowinterface.com/forums/forumdisplay.php?f=140)
-   -   Lua macro tutorial (https://www.wowinterface.com/forums/showthread.php?t=44492)

Macro-Wow 09-24-12 12:51 PM

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

Dridzt 09-24-12 01:20 PM

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.

Dridzt 09-24-12 01:28 PM

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.

Macro-Wow 09-24-12 03:08 PM

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?

Phanx 09-24-12 03:16 PM

%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".

SDPhantom 09-24-12 03:20 PM

%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.

Seerah 09-24-12 03:25 PM

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. :)

Dridzt 09-24-12 03:33 PM

Quote:

Originally Posted by Seerah (Post 264989)
<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 :o

Macro-Wow 09-24-12 06:23 PM

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