includes?
okay i have my scripts setup like this
Code:
interface in modules i have settings.lua i want to use around my ui, so i use Code:
local iamdefaultfont = "Interface\\AddOns\\suite\\media\\font\\mono.ttf" |
I think the only thing you can do is to make a global variable (or table) in a .lua file and put it in the top of your .toc file so it's loaded before your scripts.
I've not really run into this problem because most of my addons or scripts don't reuse the same textures but if they do I just put them in their own media folder inside the addon folder even though it will end up being duplicates. |
A couple of patches ago, Blizzard added a built-in mechanism to have an addon-local table, by this method:
Code:
local ADDON_NAME, ADDON_TABLE = ... |
Quote:
local settings.lua, iamdefaultfont, ect ect ect ? |
Quote:
|
Quote:
confused :P |
At the top of every Lua file loaded from the ToC file -
Code:
local ADDON_NAME, common = ... The second variable, which I have called "common", is the table which is only visible to the files which are loaded from the ToC file. Now, in every file, you can do things like this: Code:
function common.DoSomething() |
@Torhal: ty for info, didn't know about addon local vars :)
@mankeluvsit If you need your "settings" just in one addon - what Torhal sad :P If you need it across more addons (as you sad "in your ui"), then you would have to make a global table, and put all your vars in it. e.g. Code:
MY_SETTINGS = { Then you could use those variables across all addons. e.g. Code:
local myfont = MY_SETTINGS.defaultfont Code:
local sometext = parrentFrame:CreateFontString(nil, 'OVERLAY', 'MY_SETTINGS.defaultfont') Another way to do it would be something like: Code:
MY_SETTINGS = {} Code:
MY_SETTINGS.defaultfont = "Interface\\AddOns\\suite\\media\\font\\mono.ttf" |
Quote:
utils.lua Code:
local addonName, addonTable = ... Code:
local addonName,addonTable = ... Edit: It can also be used to plug in a saved variable table. fontDB.lua Code:
local addonName, addonTable = ... I use this functionality alot in my latest addons and will slowly incorporate them into my next set of updates to my old ones. And for functions that do not need to be shared across addons or files I keep to the normal local function set up. |
All times are GMT -6. The time now is 01:18 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI