Try moving OnReady from ADDON_LOADED to PLAYER_LOGIN. Your SavedVariables will have been loaded by the game when this event fires and it only fires once.
Don't forget to remove your old SV .lua file(s) before trying.
Lua Code:
function BattleDex.OnReady()
-- init database
if not BattleDexDB then
BattleDexDB = {
pets = {},
}
end
if not BattleDexPrefs then
BattleDexPrefs = {}
for k,v in pairs(BattleDex.default_options) do
if not BattleDexPrefs[k] then
BattleDexPrefs[k] = v
end
end
end
GameTooltip:HookScript("OnTooltipSetUnit", BattleDex.AlterTooltip);
end
function BattleDex.OnEvent(frame, event, ...)
if (event == 'PLAYER_LOGIN') then
BattleDex.OnReady();
end
if (event == 'PET_BATTLE_OPENING_DONE') then
BattleDex.RecordBattle();
end
end
-- ...
BattleDex.EventFrame:RegisterEvent("PLAYER_LOGIN");
BattleDex.EventFrame:RegisterEvent("PET_BATTLE_OPENING_DONE");