Thread Tools Display Modes
01-19-21, 03:17 AM   #1
Jumpercable
A Murloc Raider
Join Date: Jan 2021
Posts: 7
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.

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


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

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

-----------------------------
-- 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:SetWidth(420)
	EZTest_Config:SetHeight(400)
	EZTest_Config:SetToplevel(true)
	EZTest_Config:Hide()
	EZTest_Config.name = "EZ TEST"
	InterfaceOptions_AddCategory(EZTest_Config)
	EZTest_Config.help = EZTest_Config:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
	EZTest_Config.help:SetText("EZ TEST")
	EZTest_Config.help:SetPoint("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)
	EZTest_Config.DismountCheck:SetChecked(EZTestData.Config_Dismount)
  function EZTest_Config.DismountCheck.setFunc(state)
		EZTestData.Config_Dismount = state
    lib.ApplyLayout()
	end
  
  	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)
	EZTest_Config.FlyingCheck:SetChecked(EZTestData.Config_Flying)
  function EZTest_Config.FlyingCheck.setFunc(state)
		EZTestData.Config_Flying = state
    lib.ApplyLayout()
  end
	

end

Last edited by Jumpercable : 01-19-21 at 05:17 AM.
  Reply With Quote
01-19-21, 05:01 AM   #2
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
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?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
01-19-21, 05:21 AM   #3
Jumpercable
A Murloc Raider
Join Date: Jan 2021
Posts: 7
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

Last edited by Jumpercable : 01-19-21 at 05:34 AM.
  Reply With Quote
01-19-21, 06:59 AM   #4
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
OK, can you share your toc file? If your SavedVariables are not working, we first have to make sure it is setup there correctly.
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
01-19-21, 02:26 PM   #5
Jumpercable
A Murloc Raider
Join Date: Jan 2021
Posts: 7
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.

Toc:

Code:
## Interface: 90002
## Title: EZ Test
## Version: 1.2.2
## Author: Jumpercable
## Notes: Mount addon.
## SavedVariablesPerCharacter: EZTestData
EZ Test.lua
  Reply With Quote
01-19-21, 02:59 PM   #6
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
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?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~

Last edited by LudiusMaximus : 01-19-21 at 03:03 PM.
  Reply With Quote
01-19-21, 04:27 PM   #7
Taudier
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 53
you have to define EZTestData first
  Reply With Quote
01-19-21, 04:42 PM   #8
Jumpercable
A Murloc Raider
Join Date: Jan 2021
Posts: 7
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.
  Reply With Quote
01-19-21, 06:22 PM   #9
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
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
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
01-19-21, 07:57 PM   #10
Jumpercable
A Murloc Raider
Join Date: Jan 2021
Posts: 7
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.
  Reply With Quote
01-20-21, 02:54 AM   #11
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Of course, if there is an error anywhere in your lua file (red bugsack minimap icon) it's likely that nothing will work.
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
01-20-21, 05:23 AM   #12
Jumpercable
A Murloc Raider
Join Date: Jan 2021
Posts: 7
Might have to try the xml approach to frames.
  Reply With Quote
01-20-21, 12:18 PM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Or you could figure out the cause of the error and remedy it?
__________________
"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

WoWInterface » Developer Discussions » General Authoring Discussion » Having trouble with multiple frames and switching data between them.

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