WoW:API setglobal: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(→Details: Explain how getfenv() works equally well) |
||
| Line 26: | Line 26: | ||
== Example == | == Example == | ||
script setglobal( "MyVariable", 1234 ); | |||
script setglobal( "MyVariable", 1234 ); | |||
=== Result === | |||
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 globalenv = getfenv(); | |||
local prevval = globalenv["MyVariable"]; ''-- "getglobal()"'' | |||
globalenv["MyVariable"] = 1234; ''-- "setglobal()"'' | |||
Revision as of 08:36, 17 July 2006
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()"