Thread Tools Display Modes
03-29-16, 12:58 PM   #1
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Caching the entire spellbook securely?

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:
  1. -- Run this in response to a talent update
  2. local function SecureSpellBookUpdate()
  3.     Cursor:Execute([[ SPELLS = wipe(SPELLS) ]])
  4.     for id=1, MAX_SPELLS do
  5.         local ok, err, _, _, _, _, _, spellID = pcall(GetSpellInfo, id, "spell")
  6.         if ok then
  7.             Cursor:Execute(format([[
  8.                 SPELLS[%d] = %d
  9.             ]], spellID, id))
  10.         else
  11.             break
  12.         end
  13.     end
  14. end
  15.  
  16. Cursor:SetAttribute("RefreshActions", [[
  17.     Helpful = wipe(Helpful)
  18.     Harmful = wipe(Harmful)
  19.     for actionButton in pairs(Actions) do
  20.         local action = actionButton:GetAttribute("action")
  21.         local id = action >= 0 and action <= 12 and (PAGE-1) * 12 + action or action >= 0 and action
  22.         if id then
  23.             local actionType, actionID, subType = GetActionInfo(id)
  24.             if actionType == "spell" and subType == "spell" then
  25.                 local spellBookID = SPELLS[actionID]
  26.                 local helpful = spellBookID and IsHelpfulSpell(spellBookID, "spell")
  27.                 local harmful = spellBookID and IsHarmfulSpell(spellBookID, "spell")
  28.                 if helpful then
  29.                     Helpful[actionButton] = true
  30.                 elseif harmful then
  31.                     Harmful[actionButton] = true
  32.                 else
  33.                     Helpful[actionButton] = true
  34.                     Harmful[actionButton] = true
  35.                 end
  36.             end
  37.         end
  38.     end
  39. ]])
__________________

Last edited by MunkDev : 03-29-16 at 01:12 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Caching the entire spellbook securely?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off