WoW:API setglobal: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
 
(→‎Details: Explain how getfenv() works equally well)
Line 26: Line 26:


== 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==
== Details ==
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. -->
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 globalenv = getfenv();
 
  local prevval = globalenv["MyVariable"];  ''-- "getglobal()"''
-[[User:Tigerheart|Tigerheart]] 21:42, 30 June 2006 (EDT)
  globalenv["MyVariable"] = 1234;            ''-- "setglobal()"''

Revision as of 08:36, 17 July 2006

WoW API < setglobal


Set a global variable, from a string.

setglobal( "globalName", value );


Parameters

Arguments

("globalName", value)
globalName
String - Name of the global you want to change.
value
Any - Value you want to set the global to.

Returns

Always returns nil.


Example

script setglobal( "MyVariable", 1234 );

Result

MyVariable = 1234


Details

As of the introduction of getfenv() into the API, setglobal() and getglobal() are somewhat superfluous. You can always do something along the lines of:

 local globalenv = getfenv();
 local prevval = globalenv["MyVariable"];   -- "getglobal()"
 globalenv["MyVariable"] = 1234;            -- "setglobal()"