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:API getglobal
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!
{{wowapi}} ''Note: getglobal and [[API_setglobal|setglobal]] are deprecated and replaced with _G[]<ref>http://forums.worldofwarcraft.com/thread.html?topicId=25626580975&sid=1</ref>. Change all references of getglobal and setglobal:'' var = getglobal(varName) --getglobal deprecated var = _G[varName] --new syntax to get a global setglobal(otherName, otherVar) --setglobal deprecated _G[otherName] = otherVar --new syntax to set a global == Description == Get a global variable, from a string. local targetGlobal = getglobal("globalName") == Arguments == :("globalName") :;globalName : String - Name of the global you want to get. == Returns == :;The value from the given string, or nil if not found == Details == This function is used to get an object if you generate the name of the object manually in your script: -- i = some_dynamic_number local curFrame = getglobal("myFrame"..i) As of the introduction of [[API getfenv|getfenv]]() into the API (as well as direct access to the table _G as a global), setglobal() and [[API getglobal|getglobal]]() are somewhat superfluous. You can always do something along the lines of: local _G = getfenv() local prevval = _G["MyVariable"] ''-- "getglobal()"'' _G["MyVariable"] = 1234 ''-- "setglobal()"'' Function calls always cost some overhead, so if a large number of getglobal calls are being made, the global table will be a faster route. Note that for few or infrequent calls the performance gain of this method is negligible (but given the lack of any loss of functionality, recommended). ''Note:'' Accessing the global table through the function getfenv() was common within addons presumably because the global '[[Dump_G|_G]]' (the direct global table) was hidden from the WoW environment. It seems to have since been uncovered, and now calling it directly for global access is possible: local _G = _G -- a local speeds up access to [[Dump_G|_G]] slightly. negligible for infrequent calls. local prevval = _G["MyVariable"] ''-- "getglobal()"'' _G["MyVariable"] = 1234 ''-- "setglobal()"''
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:Apinav
(
edit
)
Template:Editlink
(
edit
)
Template:Tocright
(
edit
)
Template:Wowapi
(
edit
)