Go to Page... |
Thread Tools | Display Modes |
02-12-17, 08:55 AM | #1 |
Would like to ask some advice regarding AceAddon-3.0
Hi all,
First of all, I would like to ask an excuse as this thread is more related to Ace3 framework than generic lua questions. Tracker.lua Lua Code:
Experience.lua Lua Code:
As I have hinted above, I am currently playing around with Ace3 & SavedVariables and making super simple addon which just displays player's name, level and exp amount. (Yeah... I am aware of that this kind of addon is useless, it's just for studying ) Q: Why am I using Ace3? A: Like I've said, I am using it for studying(?) purpose, and was interested in its AceEvent-3.0 functions as well. Q: What is saved in SavedVariables? A: It currently stores the point data of the frame like point, relativeFrame, relativePoint, ofsx, ofsy. However, as you can see above, my code structures are currently messed up (not optimized) and am still not confident of using them. Thus, I would like to ask some advice to those who are using either of them. The reason that I've utilized ADDON_LOADED event is because of the db, SavedVariables. If I am understanding correctly, the loading is done by the following orders. 1. Load lua files 2. :OnInitialize() function gets called 3. ADDON_LOADED event gets called So, if I pull those initialization codes out from :ADDON_LOADED() function, it will just crash as it cannot find db. That's pretty much all of what I can explain(?) so far. Could I please get some advice regarding what I have done? (Especially in terms of optimization) Thank you! Last edited by Layback_ : 02-12-17 at 09:08 AM. |
|
02-12-17, 04:37 PM | #2 |
OnIntialize() == ADDON_LOADED, except that OnInit() already takes care of the unregistering and filtering out for your addon. You do not need both.
You would want to set up your DB in OnInit() because it only fires once. Same with setting up things like keybindings, creating frames, etc. OnEnable() is for registering events and library callbacks, along with other set up things that you might want to track on and off. OnDisable() is for unregistering events and callbacks, and clearing out variables (not saved variables) that you want wiped or assign to nil when the addon is in "standby" mode. |
|
02-12-17, 05:05 PM | #3 | |
Thank you for your advice. So, once I set up my DB in :OnInitialize() function, the best place to create and set up those frame and font strings in ADDON_LOADED() function would be :OnEnable() function? Moreover, is it okay to create multiple :OnEnable() functions in different lua files within a single addon? |
||
02-12-17, 07:58 PM | #4 |
1) No. Because OnEnable can fire multiple times, and you should be creating frames once, then reusing them. Same with font strings, or any other create once, reuse element.
OnEnable can fire when you reload the UI, or when the user toggles your addon on/off if you have such a feature. 2) No. Mainly because that doesn't exist. There is only one OnInitialize function, one OnEnable, and one OnDisable. You should look at the full Ace3 documentation; it is very thorough, except for handling modules. Also, ignore the parts about embeds.xml and list any files and libraries directly in the .toc file. https://www.wowace.com/projects/ace3...etting-started |
|
02-12-17, 08:35 PM | #5 | |
I get the idea where I should create frames, fontstrings and so on once and re-use them when they are needed, but still ain't sure of where would be the best spot to do so... Would it be just top of the lua file? A function that is called on event fires? Or any other places? I guess the answer could vary based on the structure of the addon, but would like to know some cases. Last edited by Layback_ : 02-12-17 at 08:39 PM. |
||
02-12-17, 08:55 PM | #6 | |
Since it is something that only needs to be done once when the addon is loaded, it doesn't need any events to create it. For Example I'll use the frame code in my addon: This is literally the top part of my lua file You can ignore the events and {} in the first line, since I used a table to register my events and that sets up the empty table. My addon does not use Ace, but it's one example for you anyways. Code:
--Create the Frame local Addon, events = CreateFrame("Frame", "LegionHonor", UIParent), {}; Addon:SetWidth(175); Addon:SetHeight(180); Addon:SetPoint("CENTER", UIParent, "CENTER"); Addon:SetMovable(true); Addon:EnableMouse(true); Addon:RegisterForDrag("LeftButton"); Addon:SetScript("OnDragStart", Addon.StartMoving); Addon:SetScript("OnDragStop", Addon.StopMovingOrSizing); Addon:SetClampedToScreen(true); Addon.Title = Addon:CreateFontString("LegionHonor_Title", "OVERLAY", "GameFontNormal"); Addon.Title:SetPoint("TOP"); Addon.Title:SetText("Legion Honor"); local tex = Addon:CreateTexture(nil, "BACKGROUND") tex:SetAllPoints() tex:SetColorTexture(0, 0, 0, 0.5) --Add the text Addon.PrestigeLevelText = Addon:CreateFontString("LegionHonor_PrestigeText", "OVERLAY", "GameFontNormal"); Addon.PrestigeLevelText:SetPoint("LEFT", 0, 60); Addon.PrestigeLevelText:SetText("Prestige Level"); Addon.HonorLevelText = Addon:CreateFontString("LegionHonor_HonorLevelText", "OVERLAY", "GameFontNormal"); Addon.HonorLevelText:SetPoint("LEFT", 0, 30); Addon.HonorLevelText:SetText("Honor Level"); Addon.HonorAmountText = Addon:CreateFontString("LegionHonor_HonorText", "OVERLAY", "GameFontNormal"); Addon.HonorAmountText:SetPoint("LEFT", 0, 0); Addon.HonorAmountText:SetText("Current Honor"); Addon.HonorGoalText = Addon:CreateFontString("LegionHonor_HonorGoalText", "OVERLAY", "GameFontNormal"); Addon.HonorGoalText:SetPoint("LEFT", 0, -30); Addon.HonorGoalText:SetText("Honor to Farm"); Addon.HonorPerHourText = Addon:CreateFontString("LegionHonor_HonorPerHourText", "OVERLAY", "GameFontNormal"); Addon.HonorPerHourText:SetPoint("LEFT", 0, -60); Addon.HonorPerHourText:SetText("Honor per Hour"); Addon.PlayerPrestigeLevel = Addon:CreateFontString("LegionHonor_PlayerPrestigeLevel", "OVERLAY", "GameFontNormal"); Addon.PlayerPrestigeLevel:SetPoint("RIGHT", 0, 60); Addon.PlayerHonorLevel = Addon:CreateFontString("LegionHonor_PlayerHonorLevel", "OVERLAY", "GameFontNormal"); Addon.PlayerHonorLevel:SetPoint("RIGHT", 0, 30); Addon.PlayerHonorAmount = Addon:CreateFontString("LegionHonor_PlayerHonor", "OVERLAY", "GameFontNormal"); Addon.PlayerHonorAmount:SetPoint("RIGHT", 0, 0); Addon.HonorGoalAmount = Addon:CreateFontString("LegionHonor_HonorGoalAmount", "OVERLAY", "GameFontNormal"); Addon.HonorGoalAmount:SetPoint("RIGHT", 0, -30); Addon.HonorPerHourAmount = Addon:CreateFontString("LegionHonor_HonorPerHourAmount", "OVERLAY", "GameFontNormal"); Addon.HonorPerHourAmount:SetPoint("RIGHT", 0, -60); Addon.HonorPerHourAmount:SetText("Unknown"); Last edited by briskman3000 : 02-12-17 at 08:59 PM. |
||
02-12-17, 09:28 PM | #7 |
Hi Briskman3000,
Thank you for your suggestion and example code Here's my edited version of Experience.lua: Lua Code:
I tried to get rid of ADDON_LOADED function, but once I remove that function, it won't be able to access db as it recognize db as 'nil' EDIT: Got rid of ADDON_LOADED function and immigrated stuffs into PLAYER_LOGIN function due to db issue. Last edited by Layback_ : 02-12-17 at 09:50 PM. |
|
02-12-17, 10:15 PM | #8 |
Why exactly are you setting your frame's position with a db?
Offsets are usually saved by the client automatically, so you don't need to manually do so. They should be saved to: \World of Warcraft\WTF\Account\{AccountName}\{Server}\{Character}\layout-local.txt Last edited by briskman3000 : 02-12-17 at 10:22 PM. |
|
02-12-17, 11:01 PM | #9 |
I stored them to keep the same position for all other characters in this account
|
|
02-16-17, 11:41 PM | #10 |
BUMP with new question regarding AceDB-3.0
Decided to re-use this post as OP was originally a Ace3.0 related question and as I don't want to spam my threads
So, I have tried to use AceDB-3.0 for the first time and faced an issue which I can't understand. Tracker.lua Lua Code:
I have gone through AceDB-3.0 tutorial and decided to use 'global' as a data type. However, it doesn't seem to be working at the moment (maybe I'm doing something wrong) So, here's the code for where data in db are called: Lua Code:
while these lines of code are intended to save data into db: Lua Code:
This currently doesn't work as I expected, but only uses default data set in Tracker.lua even if I move frame. I'm honestly unsure of what is going wrong with my codes EDIT: I've succeeded on using pure savedvariables btw. Last edited by Layback_ : 02-16-17 at 11:58 PM. |
|
02-17-17, 02:31 PM | #11 |
With AceDB-3.0, you set up default values that are hard coded as a table. That table is passed, in OnInitialize, to AceDB.
From then on, AceDB does not write your saved variables to file unless the user changes an option. And yes, I know technically AceDB, like any AddOn, is not doing the actual writing. The moment the user changes one of the options, say self.db.global.cute from "tabby" to "Persian", then AceDB-3.0 will save that one line in your saved variables. The rest of the file will contain empty tables, because no other option has been altered from the defaults. Here is a very basic, yet working, example of how to use AceDB-3.0. Keep in mind, every question asked in this thread has been answered via example and documentation on the Ace3 API page. Lua Code:
|
|
02-17-17, 04:20 PM | #12 | |
Hi myrroddin,
Thank you for your reply. Yeah, I have gone through Ace3 tutorials, but with my lack of understandings, I wasn't able to fully understand stuffs. I apologize about that ... So, via debugging tool (addon), ViragDevTool, I could've seen that self.db.global.experience has been updated from defaults table to new data on OnDragStop event (#9 ~ #13 of 3rd code block). (Before I moved a frame, self.db.global had same data as self.db.defaults.global) defaults: Lua Code:
Updated: Lua Code:
As you have advised,
However, the problem is that the newly updated db does not seem to be stored in SavedVariables on '/reload' or even with a log out. Since, I am not using 'profile' data type (am currently using 'global'), I guess I don't need to deal with those callbacks tho... Last edited by Layback_ : 02-17-17 at 04:27 PM. |
||
02-19-17, 05:42 AM | #13 | |
According WowWiki description about '/reload ui' it says the following:
As I have mentioned, I could've seen that self.db.global.experience has been updated as I move the frame, but the changed value doesn't seem to be updated in (applied to) SavedVariables. Everytime, I '/reload ui', the frame utilizes defaults values to set its position, and self.db.global.experience re-copies the default values. I am so confused now The code hasn't been changed since my last reply (which is right above), and have only been testing and researching since yesterday... EDIT: Just found that even those defaults data are removed from SavedVariables as I log out my toon and I guess this is because those data are same as default values like myrroddin explained above (if I am getting it correctly). Last edited by Layback_ : 02-19-17 at 05:55 AM. |
||
02-19-17, 10:19 AM | #14 |
Maybe I am not seeing it because you have only posted snippets (or because I don't understand ace3), but I don't see where the db variables are declared in the global namespace to allow them to be writable to savedvariables.
|
|
02-19-17, 02:16 PM | #15 |
Hi briskman3000,
I have the following lines of code in my Tracker.lua Lua Code:
So, my db is located inside the Engine, that Engine is located inside addon's namespace table and finally that table is globalized with name of this addon But, would this matter? Last edited by Layback_ : 02-19-17 at 02:28 PM. |
|
02-19-17, 06:21 PM | #17 |
I don't see any global variables, all locals, which can't be written to SV file
|
|
02-19-17, 06:38 PM | #18 | ||
Code:
## Interface: 70100 ## Title: Tracker ## SavedVariables: TrackerDB Tracker.lua experience.lua -------------------------------------------------------
mmmmm.... Give me a sec I'll re-check it! EDIT: Did you mean by that you don't see TrackerDB which I declared as SV in TOC file? I thought that using AceDB-3.0 would manage it by itself as I give it a correct name, wouldn't it? Maybe I was wrong D:... EDIT2: The code that I've posted are entire parts which interact with db and as the rest are only initialization part of frames, fontstrings, etc. Last edited by Layback_ : 02-19-17 at 06:54 PM. |
|||
02-19-17, 09:20 PM | #19 |
I took a quick look at the acedb3 info, and from what I can tell (I never used Ace so my complete understanding might be off), you have 2 issues.
This code is where you set up the addon variable to use Ace. Lua Code:
This variable "E" is being localized and cannot be saved to the SV file. In addition, (if my understanding of how Ace works is correct), you are attempting to use the SV of "TrackerDB", but since you are defining the variable "E" into Ace, it is actually using the variable "EDB" as the database variable. I may be wrong with the Ace related stuff, but that is how I see it. Try changing that line to: Lua Code:
and see if that fixes it EDIT: You may also have to change any other "E" references to "Tracker" in your code. Last edited by briskman3000 : 02-19-17 at 09:25 PM. |
|
WoWInterface » Developer Discussions » Lua/XML Help » Would like to ask some advice regarding AceAddon-3.0 |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|