View Single Post
03/24/14, 03:01 PM   #8
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
I believe the first var1 is classed as global across all addons and is the same as adding it to the _G table.

I am not sure if ESO has the equivalent of the addon wide data table but that would be the only way to be addon wide across all files for just a single addon.



Lua Code:
  1. globalVar = "All Addons can see me"
  2.  
  3. local localVar = "This file can see me"
  4.  
  5. function globalFunc = All addons can use me
  6. global globalFunc = function() ... same as above
  7.  
  8. local function localFunc = Only this file can use me
  9. local localFunc = function() .. same as above

Lua Code:
  1. local function aFunc()
  2.    local localVar = "Only this function has access to me"
  3.    return localVar  ... unless I return it so that they can use it
  4. end

Lua Code:
  1. for I = 1,10 do
  2.    local localVar1  = "available to the whole for loop"
  3.    if I == 4 then
  4.       local localVar2 = "available only to the if block"
  5.    end
  6. end

Hope these and the other comments help you understand how scope works.

Last edited by Xrystal : 03/24/14 at 03:03 PM.
  Reply With Quote