WoWInterface (
-   General Authoring Discussion (
-   -   Having trouble with multiple frames and switching data between them. (

Jumpercable 01-19-21 03:17 AM

Having trouble with multiple frames and switching data between them.
Hi guys, my names Jumpercable, author of EZ Mount addon.

Ive been trying to find a way to add options to my addon using: InterfaceOptions_AddCategory()

Im struggling to get the SavedVariablesPerChar into the options frame, and then any changes saved back when the player_logout event fires ( my belief is that it should auto write the savedvariables per char without any extra code ).

The purpose of this is to let me load the savedvariablespercharacter and update the options frame based on saved variables. If the options are changed the variables are saved on logout. The slash command is what my addon uses to run from an ingame macro.
Heres some code ive being trying to work with before adding it into my addon:
Any advice here or if i can even do this, any help is appreciated.


local EZTest_Main = CreateFrame("Frame","EZTest")
local EZTest      = CreateFrame("Button","EZTest",EZTest_Main,"SecureActionButtonTemplate")

EZTest:SetScript("OnEvent", function(self,event,...)
    if type(EZTestData) ~= "table" then
      EZTestData = {}
      EZTestData.Config_Flying = 0
      EZTestData.Config_Dismount = 0
      ChatFrame1:AddMessage('EZ Mount: Initial variables set for '..UnitName("player"))
      print(EZTestData.Config_Flying, EZTestData.Config_Dismount)
      if not EZTestData.Config_Flying then
        EZTestData.Config_Flying = 0
        ChatFrame1:AddMessage('Empty Data for Flying')
        if EZTestData.Config_Flying == 0 then
          ChatFrame1:AddMessage('No flying')
                  if not EZTestData.Config_Dismount then
        EZTestData.Config_Dismount = 0
        ChatFrame1:AddMessage('Empty Data for Dismount')
        if EZTestData.Config_Dismount == 0 then
          ChatFrame1:AddMessage('No Dismount')

SlashCmdList["EZTest"] = function(msg)
  print(EZTestData.Config_Flying,' Config Variable') 

-- Create GUI for options ---
--[[Use Blizzards config frame. We do not use the Configator lib]]
function Create_GUI()
  if EZTest_Config then return end
        EZTest_Config = CreateFrame("Frame", "EZTest Options", EZTest_Main, UIParent)
        EZTest_Config:Hide() = "EZ TEST"
        InterfaceOptions_AddCategory(EZTest_Config) = EZTest_Config:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")"EZ TEST")"TOPLEFT", EZTest_Config,"TOPLEFT" , 12, -20)
  --- Add UI changable elements
        EZTest_Config.DismountCheck = CreateFrame("CheckButton", "EZTESTDISMOUNT", EZTest_Config, "InterfaceOptionsCheckButtonTemplate")
        EZTESTDISMOUNTText:SetText("Enable Dismount while in air")
        EZTest_Config.DismountCheck:SetPoint("LEFT", EZTest_Config, "TOPLEFT", 10, -50)
  function EZTest_Config.DismountCheck.setFunc(state)
                EZTestData.Config_Dismount = state
          EZTest_Config.FlyingCheck = CreateFrame("CheckButton", "EZTESTFLYING", EZTest_Config, "InterfaceOptionsCheckButtonTemplate")
        EZTESTFLYINGText:SetText("Use flying mounts when you cannot fly")
        EZTest_Config.FlyingCheck:SetPoint("LEFT", EZTest_Config, "TOPLEFT", 10, -70)
  function EZTest_Config.FlyingCheck.setFunc(state)
                EZTestData.Config_Flying = state


LudiusMaximus 01-19-21 05:01 AM

Hello and welcome!

Could you wrap your code in the [ CODE ] or [ highlight="Lua"] tags? (The Buttons above your advanced editing text box.) This makes reading much easier.

Also, I have not fully understood what your problem is.
Where in your code is the positon that does not do what you want it to do?

Jumpercable 01-19-21 05:21 AM

Hi Ludius, sorry first time user didnt know where to add the code blocks, since been fixed.

Heres what this code should do:
1) Load SavedVariables per charater
2) Update the config gui ( in interface>addons ) with the loaded data or set the 2 toggles to blank if no variables are found ( new toon etc ). This isnt updating.
3) On log out the SavedVariables per characted should update the addon.lua file in their respective folders ( not happening ).
4) The changes from the config gui should be accessable throughout the addon.

In terms of where the issue is, i cannot pinpoint it exactly. The gui isnt updating, the changes to the options gui are not being saved. The variables from the gui are not accessable from outside the gui i.e

1) Option 1 is set to true ( from saved variables )
2) Option 1 is changed to false from the options gui
3) Option 1 is accessable to other parts of the addon
4) on player logout Option 1 is saved as False in the saved variables
5) on log in Option is is set to False in the gui

LudiusMaximus 01-19-21 06:59 AM

OK, can you share your toc file? If your SavedVariables are not working, we first have to make sure it is setup there correctly.

Jumpercable 01-19-21 02:26 PM

hey mate, the saved variables is working correctly as wiping the data.lua file from the realm>toon folder and logging in/out of a new toon builds a new data.lua file but it doesnt save any changes made from the gui.



## Interface: 90002
## Title: EZ Test
## Version: 1.2.2
## Author: Jumpercable
## Notes: Mount addon.
## SavedVariablesPerCharacter: EZTestData
EZ Test.lua

LudiusMaximus 01-19-21 02:59 PM

Have you checked if your setFuncs get executed as expected?

Lua Code:
  1. function EZTest_Config.DismountCheck.setFunc(state)
  2.   print("-----> DismountCheck.setFunc", state)
  3.   EZTestData.Config_Dismount = state
  4.   lib.ApplyLayout()
  5. end

PS: You also know that changes are only written back to the saved variable files once you /reload or exit the game, right?

Taudier 01-19-21 04:27 PM

you have to define EZTestData first

Jumpercable 01-19-21 04:42 PM

Hey mate, yes was aware of the variables only being written to the .lua file on logout, unlike the SavedVariables which only get written on game exit.

I have put print statements inside the function block but they do not print any information out. Putting print statement outside the block works once when the addon loads but not if opened in game to change options.

I have tried to see if that was a bug by placing the code inside the same function block inside another addon (Norgannas slidebar from the auctioneer pack). Same thing happens there, doesnt print inside the block.

LudiusMaximus 01-19-21 06:22 PM

I'm not sure, if this works:
Lua Code:
  1. function EZTest_Config.DismountCheck.setFunc(state)
  2.   EZTestData.Config_Dismount = state
  3.   lib.ApplyLayout()
  4. end

Try this and put a print in there to see if anything is happening at all when you click the button:
Lua Code:
  1. EZTest_Config.DismountCheck.setFunc = function(state)
  2.   print("This is the DismountCheck button getting", state)
  3.   EZTestData.Config_Dismount = state
  4.   lib.ApplyLayout()
  5. end

Jumpercable 01-19-21 07:57 PM

Still nothing, and it turns out the addon I was using as a basis isnt working either. Might be that or the libD errors Im seeing in bugsack.

LudiusMaximus 01-20-21 02:54 AM

Of course, if there is an error anywhere in your lua file (red bugsack minimap icon) it's likely that nothing will work.

Jumpercable 01-20-21 05:23 AM

Might have to try the xml approach to frames.

Seerah 01-20-21 12:18 PM

Or you could figure out the cause of the error and remedy it?

All times are GMT -6. The time now is 05:11 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI