WoW:API setglobal: Difference between revisions

m
no edit summary
(setglobal is deprecated and replaced with _G[])
mNo edit summary
Line 1: Line 1:
{{wowapi}}
{{wowapi|toc=0}}
 
Set a global variable, from a string.
[[API_getglobal|getglobal]] and setglobal are deprecated and replaced with _G[]<ref>http://forums.worldofwarcraft.com/thread.html?topicId=25626580975&sid=1</ref>. Their functionality will be removed from the game at a future date. Change all references of getglobal and setglobal:
setglobal( "globalName", value )
 
  var = getglobal(varName)       --getglobal deprecated
  var = _G[varName]              --new syntax to get a global


  setglobal(otherName, otherVar)  --setglobal deprecated
== Deprecation ==
  _G[otherName] = otherVar        --new syntax to set a global
Both [[API_getglobal|getglobal]] and setglobal are deprecated and replaced with the '_G[]' <ref>http://forums.worldofwarcraft.com/thread.html?topicId=25626580975&sid=1</ref> the global table. Their functionality will be removed from the game at a future date.


Replace all references of 'getglobal':
var = getglobal(varName)      --getglobal deprecated
var = _G[varName]              --new syntax to get a global


Set a global variable, from a string.
Replace all references of 'setglobal':
  setglobal( "globalName", value )
  setglobal(otherName, otherVar) --setglobal deprecated
_G[otherName] = otherVar      --new syntax to set a global


== Parameters ==
== Parameters ==
Line 34: Line 35:
   local prevval = _G["MyVariable"]  ''-- "getglobal()"''
   local prevval = _G["MyVariable"]  ''-- "getglobal()"''
   _G["MyVariable"] = 1234            ''-- "setglobal()"''
   _G["MyVariable"] = 1234            ''-- "setglobal()"''
Function calls always cost some overhead, so if a large number of getglobal calls are being made, the getfenv table will be a faster route.  Note that for few or infrequent calls the performance gain of this method is negligible.
Function calls always cost some overhead, so if a large number of getglobal calls are being made, the getfenv table will be a faster route.  Note that for few or infrequent calls the performance gain of this method is negligible.
== References ==
{{Reflist}}