WOW Gold Home --> So what is a script?

The WoW UI is controlled by code written with the Lua scripting language. You can take advantage of this scripting system in a macro with the /run command (equivalent to /script--I use /run to save a few characters). The whole script must be on one line, though you can have multiple /run commands in a single macro.

A full treatment of Lua and programming in general is well beyond the scope of this document. However, if you have some programming experience, you should head over to http://www.lua.org/pil/ to learn the basics of Lua and if you don't have any programming experience, you may want to check out http://pine.fm/LearnToProgram/ to get a foundation of the concepts used in scripts.

Blizzard provides many functions (called the API) which the Lua scripts can use to control the UI. You can view the API and other features of the UI system over at http://www.wowwiki.com/Interface_Customization (if you spend any considerable time with scripts and/or addons, WoWWiki will be indispensable). I can't possibly cover all the details of the UI environment, so I will simply present you with one of my favorite scripts as an example. See the previously linked references and the Mod Author Resources sticky (http://forums.worldofwarcraft.com/thread.html?topicId=11381244&sid=1) for more information.

The following macro (on which I based my CCWarn addon) will whisper everyone in your raid to change their targets if they have the same target as you. This is to help keep them from breaking the sheep that this macro casts as well.
/cast Polymorph
/run for i=1,GetNumRaidMembers()-1 do local u,t="raid"..i,"target"if UnitIsUnit(u..t,t)then SendChatMessage("Change targets! Trying to sheep...","WHISPER",nil,UnitName(u))end endThere are two reasons that it looks as obfuscated as that. First, there is the 255 character limit; you often need to take certain shortcuts in order to get a script to fit in a macro. Second, you have to keep the entire script on one line. Under more ideal circumstances, that code would look more like:
for i = 1, GetNumRaidMembers() - 1 do
local unit = "raid"..i
if UnitIsUnit(unit.."target", "target") then
SendChatMessage("Change targets! Trying to sheep...", "WHISPER", nil, UnitName(unit))
end
end