Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:Lua basics
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Accuracy|Needs to have more lua file specific info. A bit too general.}} {{wow/uihowto}} The ''[[World of Warcraft]]'' game client provides many functions available for use in '''[[Lua]] script files''' provided by [[AddOn]]s. These functions are the WoW API, are also used by [[Blizz]]ard to build the game client interface. They allow addons to query information about the player and the game world, to receive notifications (events) when the player interacts with the game world, and to trigger player actions like changing target, casting spells, using professions, using vehicles, joining a group, etc. === Global variables in Lua === By default any new variable you create in Lua scripts is global, meaning the variable can be accessed (and overwritten) by other scripts that happens to use the same variable name. To create local variables, precede the new variable with the keyword "local". Local variables are visible (and accessible) only from the file or block in which they are created. All AddOns in World of Warcraft share the same global variables. Considering many players have lots of AddOns installed and loaded at the same time, it quickly follows that AddOns should avoid simple names for their global variables. Otherwise it is rather easy for two AddOns to declare and use the same variable, ending with one of the AddOns overwriting that variable for the other. For this reason you should always use local variables everywhere in your script files, and only use a single global variable, or a couple of them, with a longer name specific to your AddOn (so it is unlikely other AddOn will use the same name, for example: "RoleBuffAddOn"). Use this global name for a Lua object (table), that includes all other AddOn data you want to be available and visible between script files. If you only have a single script file, you can keep all your variables local. Same Lua scripts create a local variable named "m" and use it to store and retrieve data/functions for "the current module", but I suggest you use "mod" instead. For example each of your scripts could include somewhere at the start: local mod = RoleBuffAddOn; (here "RoleBuffAddOn" is a global object created by the first of your script files) This way scripts can put data and functions into the local object "mod", and they will be available to all other scripts in your AddOn. === Variable and function names === WoW API functions and event names provided by Blizzard begin with a capital letter, like IsMounted() or UnitIsUnit(). Note these are global names. For this reason you should keep your local variables and functions beginning with a lowercase letter, like combatCheckWarrior(). This way you know that new functions added by Blizzard in WoW API, will never introduce a conflict with your own function names.
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Accuracy
(
edit
)
Template:Ambox
(
edit
)
Template:Apinav
(
edit
)
Template:Discussiontab
(
edit
)
Template:Editlink
(
edit
)
Template:Wow/uihowto
(
edit
)