I'm habing trouble getting saved variables to work for saving wishlists in my addon. I found a little tutorial on WoWwiki
https://wowwiki-archive.fandom.com/w..._game_sessions that I've been consulting thus far and I'm obviously hitting one of the pitfalls mentioned in the article where I'm loading the variables wrong and overwriting something. Sadly the article doesn't give me any further hints and I've tried to move the variable load around without much results.
So as a small preamble here's some logic what the addon does:
Create the main window --> Create all the raid tabs --> Populate the raid tabs with all the elements as they are created by the previous function. By default, open the Kara tab and do a full (kara) item database search (the search is done before tabs are created). By default the wishlist is empty.
I would like the wishlist to default to either empty, or to load the last known one. After a raid tab is created and it's elements are created (this is where im trying to load the wishlist as well), the default kara tab gets opened, which is where I get a nil error indicating to me that the loading of the wishlist overwrote something.
This is the error im getting. Googling around this apparently indicates that whatever SetPoint is being called for doesn't exist.
Code:
Message: Interface\AddOns\WishlistLC\config.lua:89: attempt to call method 'SetPoint' (a nil value)
Time: Sun May 30 15:38:46 2021
Count: 1
Stack: Interface\AddOns\WishlistLC\config.lua:89: attempt to call method 'SetPoint' (a nil value)
[string "@Interface\AddOns\WishlistLC\config.lua"]:89: in function <Interface\AddOns\WishlistLC\config.lua:84>
[string "@Interface\AddOns\WishlistLC\config.lua"]:204: in function <Interface\AddOns\WishlistLC\config.lua:191>
[string "@Interface\AddOns\WishlistLC\config.lua"]:360: in function <Interface\AddOns\WishlistLC\config.lua:333>
[string "@Interface\AddOns\WishlistLC\config.lua"]:377: in function `CreateMenu'
[string "@Interface\AddOns\WishlistLC\config.lua"]:34: in function `?'
[string "@Interface\AddOns\WishlistLC\init.lua"]:46: in function `?'
[string "@Interface\FrameXML\ChatFrame.lua"]:4825: in function `ChatEdit_ParseText'
[string "@Interface\FrameXML\ChatFrame.lua"]:4488: in function `ChatEdit_SendText'
[string "@Interface\FrameXML\ChatFrame.lua"]:4524: in function `ChatEdit_OnEnterPressed'
[string "*:OnEnterPressed"]:1: in function <[string "*:OnEnterPressed"]:1>
Locals: raid = "Karazhan"
index = 1
first_elem = true
(for generator) = <function> defined =[C]:-1
(for state) = <table> {
1 = <table> {
}
2 = <table> {
}
3 = <table> {
}
4 = <table> {
}
5 = <table> {
}
6 = <table> {
}
7 = <table> {
}
8 = <table> {
}
9 = <table> {
}
10 = <table> {
}
11 = <table> {
}
12 = <table> {
}
13 = <table> {
}
14 = <table> {
}
}
(for control) = 1
key = 1
itemButton = <table> {
toggle = <table> {
}
text = <table> {
}
highlight = <table> {
}
tooltipText = "Leather, Legs"
}
(*temporary) = nil
(*temporary) = <table> {
toggle = <table> {
}
text = <table> {
}
highlight = <table> {
}
tooltipText = "Leather, Legs"
}
(*temporary) = "TOPLEFT"
(*temporary) = KarazhanWishScrollChild {
0 = <userdata>
}
(*temporary) = "TOPLEFT"
(*temporary) = 4
(*temporary) = 0
(*temporary) = "attempt to call method 'SetPoint' (a nil value)"
namespace = <table> {
Raids = <table> {
}
currentRaid = 1
commands = <table> {
}
Print = <function> defined @Interface\AddOns\WishlistLC\init.lua:60
init = <function> defined @Interface\AddOns\WishlistLC\init.lua:66
CommitMemory = <function> defined @Interface\AddOns\WishlistLC\init.lua:96
Config = <table> {
}
ItemFrameElements = <table> {
}
filter = "all"
Kara = <table> {
}
searchResults = <table> {
}
Ketho = <table> {
}
wishlists = <table> {
}
}
which goes back to this function and the bolded line
Code:
local function UpdateWishlistFrame(raid)
local index = 1
local first_elem = true
for key, itemButton in next, namespace.wishlists[raid] do
if first_elem then
itemButton:SetPoint("TOPLEFT", _G[raid .. "WishScrollChild"], "TOPLEFT", 4, 0)
first_elem = false
else
itemButton:SetPoint("TOPLEFT", namespace.wishlists[raid][index - 1], "TOPLEFT", 0, -11)
end
itemButton:Show()
index = index + 1
end
_G[raid .. "WishScrollChild"]:SetSize(195, index * 11)
end
Right now im trying to load the wishlist before any tabs are even created. My table for wishlists is like this
Code:
namespace.wishlists = {["Karazhan"] = {},["Gruul"] = {}, ["Magth"] = {},}
the saved variables (per character obviously) version is almost the same
Code:
savedWishlists = {["Karazhan"] = {},["Gruul"] = {}, ["Magth"] = {},}
and when I load them I do it like this
Code:
]namespace.wishlists = savedWishlists
I've also registered an event in my init.lua for saving the wishlists
Code:
function namespace:CommitMemory(event, name)
if (name ~= "WishlistLC") then return end
_G[savedWishlists] = namespace.wishlists
end
local save = CreateFrame("Frame")
save:RegisterEvent("PLAYER_LOGOUT")
save:SetScript("OnEvent", namespace.CommitMemory)
Any hints would be greatly appreciated
EDIT: Sorry for the kinda messu config file. Havent cleaned it up.