ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Running into issues with LAM, first addon with it! (https://www.esoui.com/forums/showthread.php?t=6682)

Crabby654 12/15/16 02:43 PM

Running into issues with LAM, first addon with it!
 
Hey there everyone. So I created a super basic addon way long ago, bigger chat window. Basically a brainless addon to create. But now I am attempting to create my own version of the "ESO Toolbox" addon called "Expanded Options", but I want to build it myself and have more options.

I am running into issues at the very start. I want to have a settings window for this addon in the Addon Settings Menu in the default UI, but it just is not working at all. I was trying to pull parts of code from other addons with very very basic LAM settings window in the addon settings menu part of the default UI.

As an example I pulled out the AlignGrid LAM parts of the main lua and put it into my addon, I changed all the relevant information to remove anything with AlignGrid to ExpandedOptions. The addon is recognized by ESO and it shows up in the ESO Addons and is enabled. However I am seeing nothing in the Addons Settings Menu.

I am at a loss of what to do. I am an incredible newbie with LUA and making addons, I have updated a couple buy basically just updating the TOC and Library files, nothing code related.

Here is the contents of ExpandedOptions.lua
Code:

local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")

local panelData = {
                type = 'panel',
                name = 'ExpandedOptions',
                displayName = 'Expanded Options',
                author = 'Crabby654',
                version = '1.0',
                slashCommand = '/eopt',
        }

local restartRequired = '|t16:16:/esoui/art/progression/lock.dds|t You have to restart the game for these changes to take effect.';

local optionsData = {
        {
                type = 'header',
                name = 'Misc Settings',
                width = 'full',
        },
        {
                type = 'description',
                text = 'The following settings aren\'t availalbe in the standard game UI. They\'re either hidden or new and provided by this addon.',
                width = 'full',
        },
        {
                type = 'checkbox',
                name = 'Skip logos on game start',
                getFunc = function()
                                return GetCVar('SkipPregameVideos') == '1'
                        end,
                setFunc = function(value)
                                if value then
                                        SetCVar('SkipPregameVideos', '1');
                                else
                                        SetCVar('SkipPregameVideos', '0');
                                end
                        end,
                default = false,
        },
        {
                type = 'dropdown',
                name = 'Screenshot format',
                choices = {'PNG', 'BMP', 'JPG'},
                getFunc = function()
                                return GetCVar('ScreenshotFormat.2')
                        end,
                setFunc = function(value)
                                SetCVar('ScreenshotFormat.2', value)
                        end,
                width = 'full',
                default = 'PNG',
        },
        {
                type = 'dropdown',
                name = 'Rendering engine to be used',
                choices = {'DirectX 9', 'DirectX 11', 'OpenGL', 'Let the game decide'},
                getFunc = function()
                                local v = GetCVar('GraphicsDriver.7')
                                if v == 'D3D11' then
                                        return 'DirectX 11'
                                elseif v == 'D3D9' then
                                        return 'DirectX 9'
                                elseif v == 'OPENGL' then
                                        return 'OpenGL'
                                else
                                        return 'Let the game decide'
                                end
                        end,
                setFunc = function(value)
                                if value == 'DirectX 11' then
                                        SetCVar('GraphicsDriver.7', 'D3D11')
                                elseif value == 'DirectX 9' then
                                        SetCVar('GraphicsDriver.7', 'D3D9')
                                elseif value == 'OpenGL' then
                                        SetCVar('GraphicsDriver.7', 'OPENGL')
                                else
                                        SetCVar('GraphicsDriver.7', '')
                                end
                        end,
                width = 'full',
                warning = restartRequired,
                default = '',
        },
        {
                type = 'description',
                title = 'Expand UI Memory',
                text = 'By default, ESO reserves 64 MB of RAM for addons and UI code. If you\'re using many complex addons you might actually run out of memory.',
                width = 'full',
        },
        {
                type = 'description',
                text = 'LUA UI memory limit',
                width = 'half',
        },
        {
                type = 'dropdown',
                --name = 'Lua UI Memory Limit',
                choices = {'64MB', '128MB', '256MB', '512MB'},
                getFunc = function()
                                return GetCVar('LuaMemoryLimitMB') .. 'MB'
                        end,
                setFunc = function(value)
                                SetCVar('LuaMemoryLimitMB', value:gsub('MB', ''));
                        end,
                default = '64MB',
                warning = 'Reserving too much memory for the game UI might have negative impact on your game performance. Only do so if you really have to.\n\n' .. restartRequired,
                width = 'half',
        }
}

----------------------------------------------------------------------------------------------------------

---------------------------------- Addon Initialization --------------------------------------------------

local function AddOnLoaded(eventID,addonName)
        if addonName == "ExpandedOptions" then
                EVENT_MANAGER:UnregisterForEvent("ExpandedOptions_Start",eventID)
                LAM2:RegisterAddonPanel("ExpandedOptionsOptions", panelData)
        LAM2:RegisterOptionControls("ExpandedOptionsOptions", optionsData)
                setupSavedVars()
                ExpandedOptionsWindow = WM:CreateTopLevelWindow("ExpandedOptions")
                ExpandedOptionsWindow:SetAnchorFill(GuiRoot)
                ExpandedOptionsWindow:SetDrawLayer(DL_BACKGROUND)
                ExpandedOptionsWindow:SetMouseEnabled(false)
                SLASH_COMMANDS["/eopt"] = function()
                        if ExpandedOptionsWindow:IsHidden() then
                                ExpandedOptionsWindow:SetHidden(false)
                        else
                                ExpandedOptionsWindow:SetHidden(true)
                        end
                end
                createGrid()
                hideGrid()
        end
end

EVENT_MANAGER:RegisterForEvent("ExpandedOptions_Start",EVENT_ADD_ON_LOADED,AddOnLoaded)

Here are the contents of ExpandedOptions.txt
Code:

## Title: Expanded Options
## Description: Shows more options for tweaking ESO
## APIVersion: 100017
## Author: Crabby654
## Version: 1.0.0

libs\LibStub\LibStub.lua
libs\LibAddonMenu-2.0\LibAddonMenu-2.0.lua
libs\LibAddonMenu-2.0\controls\panel.lua
libs\LibAddonMenu-2.0\controls\submenu.lua
libs\LibAddonMenu-2.0\controls\button.lua
libs\LibAddonMenu-2.0\controls\checkbox.lua
libs\LibAddonMenu-2.0\controls\colorpicker.lua
libs\LibAddonMenu-2.0\controls\custom.lua
libs\LibAddonMenu-2.0\controls\description.lua
libs\LibAddonMenu-2.0\controls\dropdown.lua
libs\LibAddonMenu-2.0\controls\editbox.lua
libs\LibAddonMenu-2.0\controls\header.lua
libs\LibAddonMenu-2.0\controls\slider.lua
libs\LibAddonMenu-2.0\controls\texture.lua

ExpandedOptions.lua

; This Add-on is not created by, affiliated with or sponsored by ZeniMax
; Media Inc. or its affiliates. The Elder Scrolls® and related logos are
; registered trademarks or trademarks of ZeniMax Media Inc. in the United
; States and/or other countries. All rights reserved.
;
; You can read the full terms at:
; https://account.elderscrollsonline.com/add-on-terms


votan 12/15/16 03:09 PM

Quote:

Originally Posted by Crabby654 (Post 29128)
Hey there everyone. So I created a super basic addon way long ago, bigger chat window. Basically a brainless addon to create. But now I am attempting to create my own version of the "ESO Toolbox" addon called "Expanded Options", but I want to build it myself and have more options.

I am running into issues at the very start. I was trying to pull parts of code from other addons with very very basic LAM settings window in the addon settings menu part of the default UI.

As an example I pulled out the AlignGrid LAM parts of the main lua and put it into my addon, I changed all the relevant information to remove anything with AlignGrid to ExpandedOptions. The addon is recognized by ESO and it shows up in the ESO Addons and is enabled. However I am seeing nothing in the Addons Settings Menu.

I am at a loss of what to do. I am an incredible newbie with LUA and making addons, I have updated a couple buy basically just updating the TOC and Library files, nothing code related.

Which issue?
And look at your manifest txt at LibStub: Is it lib or libs?

Crabby654 12/15/16 03:27 PM

Quote:

Originally Posted by votan (Post 29129)
Which issue?
And look at your manifest txt at LibStub: Is it lib or libs?

Oh wow I was typing so fast I forgot haha. I edited the OP with my issue but it is basically this, I want to have a settings window for this addon in the Addon Settings Menu in the default UI, but it just is not working at all.

I also edited this line in the .txt file - libs\LibStub\LibStub.lua
It now matches the other library file locations.

Still no menu working.

Baertram 12/15/16 06:54 PM

Is the addon loaded? Did you test with d("debug message") in your addon loaded function to see how far the addon gets?
Are the variables optionData and panel data inside any function or (only local defined in this function then) or directly in the addon file (thus global locals within your addon and known to the function onAddonLoaded this way)?

votan 12/16/16 02:19 AM

Next question: Where do you define WM?

Code:

local function AddOnLoaded(eventID,addonName)
        if addonName == "ExpandedOptions" then
                EVENT_MANAGER:UnregisterForEvent("ExpandedOptions_Start",eventID)
                LAM2:RegisterAddonPanel("ExpandedOptionsOptions", panelData)
        LAM2:RegisterOptionControls("ExpandedOptionsOptions", optionsData)
                setupSavedVars()
                ExpandedOptionsWindow = WM:CreateTopLevelWindow("ExpandedOptions")
                ExpandedOptionsWindow:SetAnchorFill(GuiRoot)
                ExpandedOptionsWindow:SetDrawLayer(DL_BACKGROUND)
                ExpandedOptionsWindow:SetMouseEnabled(false)
                SLASH_COMMANDS["/eopt"] = function()
                        if ExpandedOptionsWindow:IsHidden() then
                                ExpandedOptionsWindow:SetHidden(false)
                        else
                                ExpandedOptionsWindow:SetHidden(true)
                        end
                end
                createGrid()
                hideGrid()
        end
end


Crabby654 12/16/16 09:36 AM

Quote:

Originally Posted by Baertram (Post 29131)
Is the addon loaded? Did you test with d("debug message") in your addon loaded function to see how far the addon gets?
Are the variables optionData and panel data inside any function or (only local defined in this function then) or directly in the addon file (thus global locals within your addon and known to the function onAddonLoaded this way)?

I am not sure if the addon is loading, how do I do the debug message to test it?

Quote:

Originally Posted by votan (Post 29134)
Next question: Where do you define WM?

Code:

local function AddOnLoaded(eventID,addonName)
        if addonName == "ExpandedOptions" then
                EVENT_MANAGER:UnregisterForEvent("ExpandedOptions_Start",eventID)
                LAM2:RegisterAddonPanel("ExpandedOptionsOptions", panelData)
        LAM2:RegisterOptionControls("ExpandedOptionsOptions", optionsData)
                setupSavedVars()
                ExpandedOptionsWindow = WM:CreateTopLevelWindow("ExpandedOptions")
                ExpandedOptionsWindow:SetAnchorFill(GuiRoot)
                ExpandedOptionsWindow:SetDrawLayer(DL_BACKGROUND)
                ExpandedOptionsWindow:SetMouseEnabled(false)
                SLASH_COMMANDS["/eopt"] = function()
                        if ExpandedOptionsWindow:IsHidden() then
                                ExpandedOptionsWindow:SetHidden(false)
                        else
                                ExpandedOptionsWindow:SetHidden(true)
                        end
                end
                createGrid()
                hideGrid()
        end
end


I am not...sure. Ugh maybe I bit off more than I can chew with creating an addon. I should probably have tried to create a settings with LAM from scratch instead of pulling it from another, but dang its hard to find guides for that :(

Baertram 12/18/16 11:53 AM

Look into the LAM folder (download it totally fresh without addons from www.esoui.com http://www.esoui.com/downloads/info7-LibAddonMenu.html). There is an example.lua file in there.

WM should be the WINDOW_MANAGER so you need to define it with local wm = WINDOW_MANAGER or use WINDOW_MANAGER instead of WM.

Crabby654 12/18/16 12:29 PM

Quote:

Originally Posted by Baertram (Post 29155)
Look into the LAM folder (download it totally fresh without addons from www.esoui.com http://www.esoui.com/downloads/info7-LibAddonMenu.html). There is an example.lua file in there.

WM should be the WINDOW_MANAGER so you need to define it with local wm = WINDOW_MANAGER or use WINDOW_MANAGER instead of WM.

So that was an awesome idea and didn't realize a template for it was that readily available. However I am still not getting any panel or window to show up. If it helps when I type /extopt (my slash command) it says "Invalid Command"
Alright this is what I have so far:

ExtendedOptions.txt
Code:

## Title: Extended Options
## Description: Shows more options for tweaking ESO that are available in the default UI.
## APIVersion: 100017
## Author: Crabby654
## Version: 1.0.0

libs\LibStub\LibStub.lua
libs\LibAddonMenu-2.0\LibAddonMenu-2.0.lua
libs\LibAddonMenu-2.0\controls\panel.lua
libs\LibAddonMenu-2.0\controls\submenu.lua
libs\LibAddonMenu-2.0\controls\button.lua
libs\LibAddonMenu-2.0\controls\checkbox.lua
libs\LibAddonMenu-2.0\controls\colorpicker.lua
libs\LibAddonMenu-2.0\controls\custom.lua
libs\LibAddonMenu-2.0\controls\description.lua
libs\LibAddonMenu-2.0\controls\dropdown.lua
libs\LibAddonMenu-2.0\controls\editbox.lua
libs\LibAddonMenu-2.0\controls\header.lua
libs\LibAddonMenu-2.0\controls\slider.lua
libs\LibAddonMenu-2.0\controls\texture.lua

ExtendedOptions.lua

; This Add-on is not created by, affiliated with or sponsored by ZeniMax
; Media Inc. or its affiliates. The Elder Scrolls® and related logos are
; registered trademarks or trademarks of ZeniMax Media Inc. in the United
; States and/or other countries. All rights reserved.
;
; You can read the full terms at:
; https://account.elderscrollsonline.com/add-on-terms

ExtendedOptions.lua
Code:

local panelData = {
    type = "panel",
    name = "Extended Options",
    displayName = "Extended Options",
    author = "Crabby654",
    version = "1.0.0",
    slashCommand = "/extopt",        --(optional) will register a keybind to open to this panel
    registerForRefresh = true,        --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
    registerForDefaults = true,        --boolean (optional) (will set all options controls back to default values)
}

local optionsTable = {
    [1] = {
        type = "header",
        name = "My Header",
        width = "full",        --or "half" (optional)
    },
    [2] = {
        type = "description",
        --title = "My Title",        --(optional)
        title = nil,        --(optional)
        text = "My description text to display. blah blah blah blah blah blah blah - even more sample text!!",
        width = "full",        --or "half" (optional)
    },
    [3] = {
        type = "dropdown",
        name = "My Dropdown",
        tooltip = "Dropdown's tooltip text.",
        choices = {"table", "of", "choices"},
        getFunc = function() return "of" end,
        setFunc = function(var) print(var) end,
        width = "half",        --or "half" (optional)
        warning = "Will need to reload the UI.",        --(optional)
    },
    [4] = {
        type = "dropdown",
        name = "My Dropdown",
        tooltip = "Dropdown's tooltip text.",
        choices = {"table", "of", "choices"},
        getFunc = function() return "of" end,
        setFunc = function(var) print(var) end,
        width = "half",        --or "half" (optional)
        warning = "Will need to reload the UI.",        --(optional)
    },
    [5] = {
        type = "slider",
        name = "My Slider",
        tooltip = "Slider's tooltip text.",
        min = 0,
        max = 20,
        step = 1,        --(optional)
        getFunc = function() return 3 end,
        setFunc = function(value) d(value) end,
        width = "half",        --or "half" (optional)
        default = 5,        --(optional)
    },
    [6] = {
        type = "button",
        name = "My Button",
        tooltip = "Button's tooltip text.",
        func = function() d("button pressed!") end,
        width = "half",        --or "half" (optional)
        warning = "Will need to reload the UI.",        --(optional)
    },
    [7] = {
        type = "submenu",
        name = "Submenu Title",
        tooltip = "My submenu tooltip",        --(optional)
        controls = {
            [1] = {
                type = "checkbox",
                name = "My Checkbox",
                tooltip = "Checkbox's tooltip text.",
                getFunc = function() return true end,
                setFunc = function(value) d(value) end,
                width = "half",        --or "half" (optional)
                warning = "Will need to reload the UI.",        --(optional)
            },
            [2] = {
                type = "colorpicker",
                name = "My Color Picker",
                tooltip = "Color Picker's tooltip text.",
                getFunc = function() return 1, 0, 0, 1 end,        --(alpha is optional)
                setFunc = function(r,g,b,a) print(r, g, b, a) end,        --(alpha is optional)
                width = "half",        --or "half" (optional)
                warning = "warning text",
            },
            [3] = {
                type = "editbox",
                name = "My Editbox",
                tooltip = "Editbox's tooltip text.",
                getFunc = function() return "this is some text" end,
                setFunc = function(text) print(text) end,
                isMultiline = false,        --boolean
                width = "half",        --or "half" (optional)
                warning = "Will need to reload the UI.",        --(optional)
                default = "",        --(optional)
            },
        },
    },
    [8] = {
        type = "custom",
        reference = "MyAddonCustomControl",        --unique name for your control to use as reference
        refreshFunc = function(customControl) end,        --(optional) function to call when panel/controls refresh
        width = "half",        --or "half" (optional)
    },
    [9] = {
        type = "texture",
        image = "EsoUI\\Art\\ActionBar\\abilityframe64_up.dds",
        imageWidth = 64,        --max of 250 for half width, 510 for full
        imageHeight = 64,        --max of 100
        tooltip = "Image's tooltip text.",        --(optional)
        width = "half",        --or "half" (optional)
    },
}

local LAM = LibStub("LibAddonMenu-2.0")
LAM:RegisterAddonPanel("ExtendedOptions", panelData)
LAM:RegisterOptionControls("ExtendedOptions", optionsTable)

Folders are
Extended Options -> ExtendedOptions.txt ExtendedOptions.lua libs
libs -> LibAddonMenu-2.0 LibStub LibAddonMenu-2.0.txt

Baertram 12/18/16 01:33 PM

Ok, please put your WHOLE addon, including the lua files, into a ZIP archive and upload it here so we can see all code of the addon.

If you simply put the LAM menu into your file ExtendedOptions.lua., and there is no EVENT_ADDON_LOADED int here which "enables your addon" and starts to call the LAM object etc. you won't see anything. So please provide the WHOLE code of your addon here so we can check and help you.

Thanks

Crabby654 12/18/16 03:39 PM

1 Attachment(s)
Quote:

Originally Posted by Baertram (Post 29161)
Ok, please put your WHOLE addon, including the lua files, into a ZIP archive and upload it here so we can see all code of the addon.

If you simply put the LAM menu into your file ExtendedOptions.lua., and there is no EVENT_ADDON_LOADED int here which "enables your addon" and starts to call the LAM object etc. you won't see anything. So please provide the WHOLE code of your addon here so we can check and help you.

Thanks

Alrighty here is the addon zip attached to this reply. Also this is a super basic addon I am making, essentially I just want a menu in the addon settings page in the default UI to change CVars in the usersettings file.

Ayantir 12/18/16 03:46 PM

Looked quickly at it and ...

http://wiki.esoui.com/Main_Page
http://wiki.esoui.com/Getting_Started
http://wiki.esoui.com/Writing_your_first_addon
http://wiki.esoui.com/SimpleNotebookTutorial/part1

I would also say that when you don't understand something, look at how others did and do same.

Baertram 12/18/16 04:50 PM

As I thought you are not building an addon. You are just putting some lua source code for a LAM in your file and that's all :rolleyes:
Please read the links that Ayantir provided and see how an addon must be build in the addon's lua file.
Especially the event like EVENT_ON_ADDON_LOADED etc.

The lua interpreter is reading your source code from the top of the fie downwards to the bottom so be sure to put your variables and functions etc. in the correct order, so that "called variables/functions" further down in your code will be declared above the code where they are called.

Crabby654 12/18/16 04:57 PM

Quote:

Originally Posted by Ayantir (Post 29163)
Looked quickly at it and ...

http://wiki.esoui.com/Main_Page
http://wiki.esoui.com/Getting_Started
http://wiki.esoui.com/Writing_your_first_addon
http://wiki.esoui.com/SimpleNotebookTutorial/part1

I would also say that when you don't understand something, look at how others did and do same.

Quote:

Originally Posted by Baertram (Post 29167)
As I thought you are not building an addon. You are just putting some lua source code for a LAM in your file and that's all :rolleyes:
Please read the links that Ayantir provided and see how an addon must be build in the addon's lua file.
Especially the event like EVENT_ON_ADDON_LOADED etc.

The lua interpreter is reading your source code from the top of the fie downwards to the bottom so be sure to put your variables and functions etc. in the correct order, so that "called variables/functions" further down in your code will be declared above the code where they are called.

Alrighty thank you for the links. I'll take a read through them and see what to do! I'm sorry if this was a super ridiculous thing to post about, I honestly thought that for what I had that at least a menu would show up, but I guess not! Time to take it all back to the drawing board.

Baertram 12/18/16 05:26 PM

Without your addon around the menu the menu will not be shown as it relies on an addon construct in the back. If your addon is not loaded the menu won't be loaded :D


All times are GMT -6. The time now is 04:48 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI