WoW:API setglobal: Difference between revisions

m
Move page script moved page API setglobal to WoW:API setglobal without leaving a redirect
No edit summary
 
m (Move page script moved page API setglobal to WoW:API setglobal without leaving a redirect)
 
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{wowapi}} __NOTOC__
{{wowapi|toc=0}}
 
Set a global variable, from a string.
setglobal( "globalName", value )


<!-- Describe the purpose of the function, exhausting detail can be saved for a later section -->
== Deprecation ==
Set a global variable, from a string.
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.


<!-- List return values and arguments as well as function name, follow Blizzard usage convention for args -->
Replace all references of 'getglobal':
setglobal( "globalName", value );
var = getglobal(varName)      --getglobal deprecated
var = _G[varName]              --new syntax to get a global


Replace all references of 'setglobal':
setglobal(otherName, otherVar) --setglobal deprecated
_G[otherName] = otherVar      --new syntax to set a global


== Parameters ==
== Parameters ==
=== Arguments ===
=== Arguments ===
<!-- List each argument, together with its type -->
:("globalName", value)
:("globalName", value)


Line 19: Line 22:


=== Returns ===
=== Returns ===
<!-- List each return value, together with its type -->
<!-- :isTrue, retVal1, retVal2-->  <!-- remove this line if it's just one value -->
:;Always returns nil.
:;Always returns nil.


== Example ==
== Example ==
<!-- If it helps, include an example here, though it's not required if the usage is self-explanatory -->
/script setglobal( "MyVariable", 1234 )
script setglobal( "MyVariable", 1234 );


====Result====
=== Result ===
<!-- If it helps, include example results here, though they are not required. You're allowed to cheat liberally since WoW isn't a command line language. -->
  MyVariable = 1234
  MyVariable = 1234


== Details ==
As of the introduction of [[API getfenv|getfenv]]() into the API, 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()"''


<!--==Details==
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.
  Details not appropriate for the main description can go here.
    REMOVE the section if you're just going to restate the intro line!
 
: Does something particularly detailed. -->
 


-[[User:Tigerheart|Tigerheart]] 21:42, 30 June 2006 (EDT)
== References ==
{{Reflist}}
Anonymous user