Navigation menu

WoW:Lua variable scoping: Difference between revisions

Jump to navigation Jump to search
m
tweak lead-in links.
m (catfix)
m (tweak lead-in links.)
Line 1: Line 1:
[[Addons]] in World of Warcraft share a single [[execution environment]]. As a result, all addons have access to the same global variables. If one addon creates a global variable named "foo," then all other addons can use (or overwrite) that same variable. This allows for some really useful things to happen; the most frequently used tactic that takes advantage of this feature is [[HOWTO:_Hook_a_Function|hooking]]. Unfortunately, this can also cause some problems in addons. They will conflict if they both try to use the same name for a variable. As a result, addon authors must ensure that their addons don't conflict by doing one (or more) of the following:
[[Addons]] in World of Warcraft share a single execution environment. As a result, all addons have access to the same global variables. If one addon creates a global variable named "foo," then all other addons can use (or overwrite) that same variable. This allows for some really useful things to happen; the most frequently used tactic that takes advantage of this feature is [[Hooking functions|hooking]]. Unfortunately, this can also cause some problems in addons. They will conflict if they both try to use the same name for a variable. As a result, addon authors must ensure that their addons don't conflict by doing one (or more) of the following:
#Using assuredly-unique names for variables, such as MyAddon_MyFrame_OnLoad
#Using assuredly-unique names for variables, such as MyAddon_MyFrame_OnLoad
#Making their addons [[Object_Oriented_Programming|object-oriented]]  
#Making their addons [[Object_Oriented_Programming|object-oriented]]