You can’t store the frame reference of the relative frame that f is attached to so if possible, store it’s name and retrieve it from the global table next time:
local p,r,t,x,y = f:GetPoint(1)
if r:GetName() then
r = r:GetName()
else
r = "UIParent"
end
framePosition = {p, r, t, x, y)
and to restore:
f:SetPoint(framePosition[1], _G[framePosition[2]], framePosition[3], framePosition[4], framePosition[5])
If f is attached to a frame that belongs to your addon, you don’t need to store r
framePosition = {p, t, x, y)
f:SetPoint(framePosition[1], MyAddonFrame, framePosition[2], framePosition[3], framePosition[4])
If f is attached to a frame that doesn’t have a name and you can’t just attach it to UIParent then you need some way of “finding” the frame to attach too when you login.
The ADDON_LOADED event fires first when your addon loads and for every addon that loads after that (you don’t get the event for any addons that load before yours).
If the frame you’re saving/restoring belongs to another addon then maybe consider using the PLAYER_LOGIN event as that fires only once, after all addons identified to load at startup have finished loading and before you enter the world.
Variables declared in the toc as ## SavedVariables
or ## SavedVariablesPerCharacter
are initially created in the global table with a nil value. When you logout/exit the value of the variables (including nil) will be written to the addons SavedVariables file(s) under the WTF folder (location being dependent on whether the variable is global or per character).
The game subsequently loads whatever has been saved in the various SV files as Globals so using unique variable names is important.
If you delete a SV file for your addon before the game starts, it will start again at nil.