Back with another question that’s probably got an obvious answer but I’m not seeing it. Trying to get my addon to remember where the user positioned it and it’s not working properly.
Saving top and left values and then reapplying them on load as follows;
In ADDON_LOADED:
if CarnSettings == nil then
CarnSettings = {
Left = 0,
Top = 0,
In PLAYER_LOGOUT:
CarnSettings = {
Top = CarnMainFrame:GetTop(),
Left = CarnMainFrame:GetLeft(),
In the main frame creation:
CarnMainFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", CarnSettings.Left, CarnSettings.Top)
Firstly, I’ll say that the “Left” or “X” value is never affected in this. It always works properly.
The problems are twofold, firstly when it’s saving postion the “Top” position is getting incremented not replaced. So if it’s at 1000 it becomes 2000 on exit, and next exit it becomes 3000 and so on. I’ve confirmed this by logging out and checking the savedvariables file.
Second, the “Top” (Y) value is positioning the frame offscreen. I’d have assumed saving the offset would save a negative value but it doesn’t appear to. So I tried using CarnSettings.Top*-1 and that helps, but it’s still not positioning properly. The form is flip-flopping between the wrong and right position on alternating reloads. Every second reload it’s in the perfect position. Every other one it’s positioned wrongly on the Y-Axis. I’m guessing that the value in the savedvariables is still being incremented but because I’m applying a negative that offsets it every second load.
So first question: Why is it incrementing the “Top” (Y axis) savedvariable instead of setting it to the current value?
Secondly, from what I understand it should be positioning the top-left corner of the addon frame based on the top-left corner of the UI (basically the whole screen). So why does the X axis work but not the Y? I noticed (https://wowwiki-archive.fandom.com/wiki/API_Region_GetBottom) that GetTop() “is only guaranteed to work after the PLAYER_LOGIN event and then, only if the object in question is being Shown”. Player Login has definitely happened but I can’t guarantee that the addon is visible when logging out (it’s often not).
For now, I’ve clamped the frame to the screen so it’s always appearing now but obviously it’s not in the right place.