Thread Tools Display Modes
11-12-16, 09:59 AM   #1
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
How do I reference an option from another file?

Setting up interface options panel for the addon.

My previous issues are all solved and I will share the addon with you guys once the interface options panel is done.

File 1:
Lua Code:
  1. local function getOptions()
  2.     if not options then
  3.         options = {
  4.             type = "group",
  5.             name = "ImmersiveHide",
  6.             args = {
  7.                 general = {
  8.                     order = 1,
  9.                     type = "group",
  10.                     name = "General Settings",
  11.                     get = optGetter,
  12.                     set = optSetter,
  13.                     args = {
  14.                         intro = {
  15.                             order = 1,
  16.                             type = "description",
  17.                             name = L["Lorem ipsum."],
  18.                         },
  19.                         alphadesc = {
  20.                             order = 2,
  21.                             type = "description",
  22.                             name = L["Lorem ipsum."],
  23.                         },
  24.                         TESTVARIABLE = {
  25.                             order = 2.2,
  26.                             type = "toggle",
  27.                             name = "TEST_VARIABLE",
  28.                             desc = L["Hello world will be shown."],
  29.                             get = function() return GetCVarBool("TESTVARIABLE") end,
  30.                             set = function(_, v) v = v and 1 or 0; SetCVar("TESTVARIABLE", v); end,
  31.                             width = "full",
  32.                         },
  33.                         alpha = {
  34.                             order = 3,
  35.                             name = L["Alpha"],
  36.                             desc = L["The transparency of stuff."],
  37.                             type = "range",
  38.                             min = 0, max = 1, bigStep = 0.01,
  39.                             isPercent = true,
  40.                         },
  41.                         fadealpha = {
  42.                             order = 4.1,
  43.                             type = "range",
  44.                             name = L["Faded Alpha"],
  45.                             desc = L["The transparency of stuff while faded."],
  46.                             get = function() return MIN_ALPHA end,
  47.                             set = function(_, v) SetCVar("MinAlpha", v); WORLD_MAP_MIN_ALPHA = v end,
  48.                             min = 0, max = 1, bigStep = 0.01,
  49.                             isPercent = true,
  50.                             disabled = function() return not GetCVarBool("Fade") end,
  51.                         },
  52.                     },
  53.                 },
  54.             },
  55.         }
  56.         for k,v in pairs(moduleOptions) do
  57.             options.args[k] = (type(v) == "function") and v() or v
  58.         end
  59.     end
  60.  
  61.     return options
  62. end

File 2:
Lua Code:
  1. local function HelloWorld()
  2.         if TESTVARIABLE = true then
  3.                 print("Hello World!")
  4.         end
  5. end
  6.  
  7. HelloWorld()
  8.  
  9. function addon:FadeIn()
  10.     UIFrameFadeIn(UIParent, 1, fadealpha, alpha);
  11. end;
  12.  
  13. function addon:FadeOut()
  14.     UIFrameFadeOut(UIParent, 1, alpha, fadealpha);
  15. end;


Variables from the first file that I want to use on the second file: TESTVARIABLE, alpha, fadealpha.

I've read plenty of addon files but they are all confusing to me because each addon creates the interface options panel in a different way and I have a really hard time identifying when they're using the configuration variables.
  Reply With Quote
11-12-16, 10:34 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Lua Code:
  1. local addonName, addonNamespace = ...

Every file loaded has access to two variables. The first is the addon name and the second is a shared namespace ( a table ). Put the data or functions you want to share into the addonNamespace.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-12-16, 11:26 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Every .lua file, not .xml files.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-12-16, 01:15 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
And to clarify, they must be loaded by the same .toc file in the same folder.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-13-16, 05:53 PM   #5
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Ok, I read about the addonTable and I think I understood that. I just need to put that line and then just put addonTable before any variable I want to use, right? Like addonTable.alpha and addonTable.fadealpha.

But I still need to make an interface options stuff. I'm taking the config.lua file from Mapster:

Lua Code:
  1. local Mapster = LibStub("AceAddon-3.0"):GetAddon("Mapster")
  2. local L = LibStub("AceLocale-3.0"):GetLocale("Mapster")
  3.  
  4. local optGetter, optSetter
  5. do
  6.     function optGetter(info)
  7.         local key = info[#info]
  8.         return Mapster.db.profile[key]
  9.     end
  10.  
  11.     function optSetter(info, value)
  12.         local key = info[#info]
  13.         Mapster.db.profile[key] = value
  14.         Mapster:Refresh()
  15.     end
  16. end
  17.  
  18. local options, moduleOptions = nil, {}
  19. local function getOptions()
  20.     if not options then
  21.         options = {
  22.             type = "group",
  23.             name = "Mapster",
  24.             args = {
  25.                 general = {
  26.                     order = 1,
  27.                     type = "group",
  28.                     name = "General Settings",
  29.                     get = optGetter,
  30.                     set = optSetter,
  31.                     args = {
  32.                         intro = {
  33.                             order = 1,
  34.                             type = "description",
  35.                             name = L["Mapster allows you to control various aspects of your World Map. You can change the style of the map, control the plugins that extend the map with new functionality, and configure different profiles for every of your characters."],
  36.                         },
  37.                         alphadesc = {
  38.                             order = 2,
  39.                             type = "description",
  40.                             name = L["You can change the transparency of the world map to allow you to continue seeing the world environment while your map is open for navigation."],
  41.                         },
  42.                         fade = {
  43.                             order = 2.2,
  44.                             type = "toggle",
  45.                             name = MAP_FADE_TEXT,
  46.                             desc = L["The map will fade out to the configured Fade Alpha level when you start moving."],
  47.                             get = function() return GetCVarBool("mapFade") end,
  48.                             set = function(_, v) v = v and 1 or 0; SetCVar("mapFade", v); end,
  49.                             width = "full",
  50.                         },
  51.                         alpha = {
  52.                             order = 3,
  53.                             name = L["Alpha"],
  54.                             desc = L["The transparency of the big map."],
  55.                             type = "range",
  56.                             min = 0, max = 1, bigStep = 0.01,
  57.                             isPercent = true,
  58.                         },
  59.                         fadealpha = {
  60.                             order = 4.1,
  61.                             type = "range",
  62.                             name = L["Faded Alpha"],
  63.                             desc = L["The transparency of the map while you are moving and the map is faded."],
  64.                             get = function() return WORLD_MAP_MIN_ALPHA end,
  65.                             set = function(_, v) SetCVar("mapAnimMinAlpha", v); WORLD_MAP_MIN_ALPHA = v end,
  66.                             min = 0, max = 1, bigStep = 0.01,
  67.                             isPercent = true,
  68.                             disabled = function() return not GetCVarBool("mapFade") end,
  69.                         },
  70.                         scaledesc = {
  71.                             order = 5,
  72.                             type = "description",
  73.                             name = L["Change the scale of the world map if you do not want the whole screen filled while the map is open."],
  74.                         },
  75.                         scale = {
  76.                             order = 6,
  77.                             name = L["Scale"],
  78.                             desc = L["Scale of the big map."],
  79.                             type = "range",
  80.                             min = 0.1, max = 2, bigStep = 0.01,
  81.                             isPercent = true,
  82.                         },
  83.                         arrowScale = {
  84.                             order = 7,
  85.                             name = L["PlayerArrow Scale"],
  86.                             desc = L["Adjust the size of the Player Arrow on the Map for better visibility."],
  87.                             type = "range",
  88.                             min = 0.5, max = 2, bigStep = 0.01,
  89.                             isPercent = true,
  90.                         },
  91.                         nl = {
  92.                             order = 10,
  93.                             type = "description",
  94.                             name = "",
  95.                         },
  96.                         poiScale = {
  97.                             order = 12,
  98.                             type = "range",
  99.                             name = L["POI Scale"],
  100.                             desc = L["Scale of the POI Icons on the Map."],
  101.                             min = 0.1, max = 2, bigStep = 0.01,
  102.                             isPercent = true,
  103.                         },
  104.                         ejScale = {
  105.                             order = 13,
  106.                             type = "range",
  107.                             name = L["EJ Icon Scale"],
  108.                             desc = L["Scale of the Encounter Journal Icons on the Map."],
  109.                             min = 0.1, max = 2, bigStep = 0.01,
  110.                             isPercent = true,
  111.                         },
  112.                         nl2 = {
  113.                             order = 20,
  114.                             type = "description",
  115.                             name = "",
  116.                         },
  117.                         hideMapButton = {
  118.                             order = 21,
  119.                             type = "toggle",
  120.                             name = L["Hide Map Button"],
  121.                         },
  122.                         disableMouse = {
  123.                             order = 22,
  124.                             type = "toggle",
  125.                             name = L["Disable Mouse"],
  126.                             desc = L["Disable the mouse interactivity of the main map, eg. to change zones."],
  127.                         },
  128.                     },
  129.                 },
  130.             },
  131.         }
  132.         for k,v in pairs(moduleOptions) do
  133.             options.args[k] = (type(v) == "function") and v() or v
  134.         end
  135.     end
  136.    
  137.     return options
  138. end
  139.  
  140. local function optFunc()
  141.     -- open the profiles tab before, so the menu expands
  142.     InterfaceOptionsFrame_OpenToCategory(Mapster.optionsFrames.Profiles)
  143.     InterfaceOptionsFrame_OpenToCategory(Mapster.optionsFrames.Mapster)
  144.     InterfaceOptionsFrame:Raise()
  145. end
  146.  
  147. function Mapster:SetupOptions()
  148.     self.optionsFrames = {}
  149.  
  150.     -- setup options table
  151.     LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("Mapster", getOptions)
  152.     self.optionsFrames.Mapster = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Mapster", nil, nil, "general")
  153.  
  154.     self:RegisterModuleOptions("Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db), "Profiles")
  155.  
  156.     LibStub("AceConsole-3.0"):RegisterChatCommand( "mapster", optFunc)
  157. end
  158.  
  159. function Mapster:RegisterModuleOptions(name, optionTbl, displayName)
  160.     moduleOptions[name] = optionTbl
  161.     self.optionsFrames[name] = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Mapster", displayName, "Mapster", name)
  162. end

From reading it I can understand that there's this MAP_FADE_TEXT variable thing with SetCVar("mapFade"). How would I make that useful in the Hello World example I first posted?

Something like 'if addonTable.SetCVar("mapFade") = 1 then print("Hello World!") end'?

I'm including this in my .toc already:

Code:
#@no-lib-strip@
Libs\LibStub\LibStub.lua
Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml

Libs\AceAddon-3.0\AceAddon-3.0.xml
Libs\AceEvent-3.0\AceEvent-3.0.xml
Libs\AceHook-3.0\AceHook-3.0.xml
Libs\AceDB-3.0\AceDB-3.0.xml
Libs\AceDBOptions-3.0\AceDBOptions-3.0.xml
Libs\AceLocale-3.0\AceLocale-3.0.xml

Libs\AceGUI-3.0\AceGUI-3.0.xml
Libs\AceConsole-3.0\AceConsole-3.0.xml
Libs\AceConfig-3.0\AceConfig-3.0.xml
#@end-no-lib-strip@
  Reply With Quote
11-13-16, 06:36 PM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I am not adding to your original question. However, in your ToC file, you need to load the Ace libraries in the same order as listed in the Ace3.toc, which, I think, is the same order as the API documentation.

You might already be doing that, but just throwing it out there.
  Reply With Quote
11-16-16, 02:06 PM   #7
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Originally Posted by Krainz View Post

From reading it I can understand that there's this MAP_FADE_TEXT variable thing with SetCVar("mapFade"). How would I make that useful in the Hello World example I first posted?

Something like 'if addonTable.SetCVar("mapFade") = 1 then print("Hello World!") end'?
Uhh... Guys? Help?
  Reply With Quote
11-16-16, 03:08 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
First, the SetCVar function is its own function, not defined/stored as part of your addon table.

Second, SetCVar sets a CVar. You need to get it's value.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-16-16, 07:54 PM   #9
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Krainz View Post
Uhh... Guys? Help?

You'd get more help if you put more effort into your posts and use addons like BugSack / Bugger to catch errors

http://meta.stackexchange.com/questi...ampire-problem
  Reply With Quote
11-17-16, 11:22 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'd suggest looking at some documentation for the WoW API functions you are using. The Get/SetCVar functions can only be used to look up and set specific built-in game options. They have nothing to do with addon options or saving addon settings.

http://wow.gamepedia.com/API_SetCVar

It seems like your goal is to save addon settings, and be able to refer to them later. Assuming that's correct, you should look at tutorials related to that goal, like this one:

http://wow.gamepedia.com/Saving_vari..._game_sessions

I'd strongly advise against copying and pasting large chunks of code from other addons (eg. Mapster's options table) that you don't understand and trying to use that as a base for your own addon -- that's a recipe for frustration and not actually learning or accomplishing anything. I'd also advise against using large libraries (eg. AceConfig) until you have a better understanding of the underlying concepts (eg. writing to and reading variables in Lua in general, and saving variables between sessions in a WoW addon in particular). Start with something simpler, like saving one setting, and then work your way up to complex nested options if that's your end goal.

If you have no programming experience at all (which seems like the case since you're having trouble with writing/reading variables, which is a very basic programming concept) I'd suggest finding a beginner's tutorial. You may not be able to find one for Lua specifically, but any scripting language -- JavaScript or Python, for example, will both have lots of tutorials out there -- will give you a better foundation, so you'll at least be able to understand the terms used in API documentation, and have a better idea of what to ask for help with.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 11-17-16 at 11:25 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How do I reference an option from another file?

Thread Tools
Display Modes

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