I'm trying to cache the entire spellbook securely, which kind of works in this hacky fashion posted below, but should I really have to use pcall to loop through the entire spellbook without causing a heap of lua errors? I tried to find appropriate functions on wowprogramming, but I came up empty handed.
The reason I want to do this is to be able to determine what kind of spell is situated on every action button. After trying a bunch of different things with the scrubbed GetActionInfo and failing to get proper results from IsHarmfulSpell/IsHelpfulSpell securely, this was the only approach that worked.
Lua Code:
-- Run this in response to a talent update
local function SecureSpellBookUpdate()
Cursor:Execute([[ SPELLS = wipe(SPELLS) ]])
for id=1, MAX_SPELLS do
local ok, err, _, _, _, _, _, spellID = pcall(GetSpellInfo, id, "spell")
if ok then
Cursor:Execute(format([[
SPELLS[%d] = %d
]], spellID, id))
else
break
end
end
end
Cursor:SetAttribute("RefreshActions", [[
Helpful = wipe(Helpful)
Harmful = wipe(Harmful)
for actionButton in pairs(Actions) do
local action = actionButton:GetAttribute("action")
local id = action >= 0 and action <= 12 and (PAGE-1) * 12 + action or action >= 0 and action
if id then
local actionType, actionID, subType = GetActionInfo(id)
if actionType == "spell" and subType == "spell" then
local spellBookID = SPELLS[actionID]
local helpful = spellBookID and IsHelpfulSpell(spellBookID, "spell")
local harmful = spellBookID and IsHarmfulSpell(spellBookID, "spell")
if helpful then
Helpful[actionButton] = true
elseif harmful then
Harmful[actionButton] = true
else
Helpful[actionButton] = true
Harmful[actionButton] = true
end
end
end
end
]])