Go to Page... |
Thread Tools | Display Modes |
11-03-22, 08:52 PM | #1 |
I am getting my butt kicked by saved variables.
Bear with me, I am learning as I go. I am making an addon that can hide the new Dragonflight Micro Menu bar. I am learning by looking at other peoples online tutorials and it's slow, but I am making progress.
I've hit a wall when it comes to saving and loading variables. I have two variables that I am attempting to load. They are Booleans called BagButtonVisable and MicroMenuVisable. I added them to the toc and successfully got them to save to the file, but they never loaded. I found some great tutorials from Phanx, I think they are a above my current level. I will include what I have done so far. Any help would be greatly appreciated. Lua Code:
|
|
11-03-22, 10:42 PM | #2 |
Saved variables are not loaded when the client loads your addon files. The variables are loaded after. You need to wait at least until the ADDON_LOADED event fires, PLAYER_LOGIN is fine.
Also, your code has a few discrepancies: HideMicroMenuDBPC does not interact with your two boolean saved variables. That table object is not a frame, so it will never trigger the PLAYER_LOGIN function. The frame object "Frame" you did register PLAYER_LOGIN to is not used anywhere else.
__________________
|
|
11-04-22, 11:21 AM | #3 |
Thanks for your help
Okay, I took some time to completely rewrite my code since I felt more confident that I understood what I was doing a little better. I now have the variables saving and loading properly, but I am not getting the desired result. I can tell that they are saving by looking at the lua file and I have a print command that fires when the game loads to tell that they are loading properly. I am trying to set the visibility of the Bag Button and the Micro Menu by using the saved variable. If the variable is FALSE then they should be hidden and visible when the variable is TRUE. But most of the time the Bag Button (for instance) will be visible even when the variable prints as FALSE. What am I doing wrong? Lua Code:
|
|
11-05-22, 09:40 AM | #4 |
Like I said, saved variables aren't loaded until the ADDON_LOADED event fires. While you solved printing them to chat, the rest of your code is still trying to use them at file load.
https://wowpedia.fandom.com/wiki/AddOn_loading_process The client reads your toc file, then it loads files you listed executing all lines of code as they load. Once all files in a toc are loaded, the client then loads the associated saved variables, then finally fires ADDON_LOADED. This means, for example, at line 37 in your second post here, "HMMVars.BagButtonVisable" will always be nil, not true or false. You also still have that unused Frame object with PLAYER_LOGIN registered. Since you haven't shared your toc file, I'm also assuming your only saved variable is currently the table object HMMVars and not the individual booleans you spoke of originally. I put everything in the PLAYER_LOGIN event: Lua Code:
__________________
|
|
WoWInterface » Developer Discussions » Lua/XML Help » I am getting my butt kicked by saved variables. |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|