Thread Tools Display Modes
01-23-10, 01:17 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
calling variables accorss modules accross files

confused yet? i am okay so heres the deal... in one file it creates the variable based on what resolution is set. it only does this once per first use of the UI, now then another file uses that variable to chose layouts. well for some reason the other file cant pick out the variables. also the addon = {} is also in another file... is that maybe the problem? do i need to make the variables global somehow? the file that is supposed to find the variables for the layouts lil chunk to do so looks like this,
lua Code:
  1. local GPartyMainEvents = CreateFrame("Frame", nil, UIParent)
  2. GPartyMainEvents:RegisterEvent("VARIABLES_LOADED")
  3.  
  4.  
  5. GrimUI.GPartyMainEvents = GPartyMainEvents
  6.  
  7. GPartyMainEvents:SetScript("OnEvent", function(self)
  8.    
  9.     if GrimUIData.GrimResolution == "1" then
  10.         GrimLayout1()      
  11.     elseif GrimUIData.GrimResolution == "2" then
  12.         GrimLayout2()
  13.     else
  14.         GrimLayout1()
  15.     end
  16.    
  17.  
  18. end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 01-23-10 at 01:29 PM.
  Reply With Quote
01-23-10, 01:36 PM   #2
Xus
A Fallenroot Satyr
 
Xus's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 25
by the looks of it GrimUIData should indeed be global (simply don't put local in front of it when you first make it hah. Or move it to a table that you already made global). Also make sure that you the resolution is already checked before the variables event!
  Reply With Quote
01-23-10, 01:59 PM   #3
cloudwolf
A Black Drake
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 87
a local variable is only good for the functoin that its in. So think of each file a as a function.
say random.lua
Code:
local myvar="hi"
function dostuff()
print(myvar) -- it will output hi
local myothervar="hi"
print(myothervar)-- it will also output hi
end
print(myvar) -- it will print hi
print(myothervar) -- this will be nil.
now lets say you have another lua file
other.lua
Code:
print(myvar) -- this will be nil
the reason its nil is because myvar is only real for random.lua
  Reply With Quote
01-23-10, 02:05 PM   #4
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Rather than make a global, at the top of each file you can add:

Code:
local _, myNamespace = ...
And then use the myNamespace (or whatever you want to call it) table for storing variables that you want to have addon-wide scope:

Code:
myNamespace.x = "hello"
myNamespace.y = 234
  Reply With Quote
01-23-10, 02:54 PM   #5
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
well i have this at the top of the core file

GrimUI = {}
local mt_grimui = {__index = GrimUI}
local modules = {}
local defaults = {__index={}}
local dummy = function() end
GrimUI.Modules = modules
GrimUI.Dummy = dummy

function GrimUI:RegisterModule(name)
local module = setmetatable({}, mt_grimui)
modules[name] = module
return module
end



with this at the top of the module files

local module = GrimUI:RegisterModule("ExpRepBar")

it was my understanding that it made all my functions work within one another
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-23-10, 07:42 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
my real problem was that i was under the impression player_login fired before addon_loaded all better now.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » calling variables accorss modules accross files


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off