Quantcast
WoWInterface - View Single Post - How to properly use CreateFramePool() ?
View Single Post
08-05-17, 12:05 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 503
Once I understood what this frame pool did, I created a very simple version I use in Decliner for generating OnUpdate responses to some filters. This way, I don't need several dedicated OnUpdate frames, just a dynamic pool that uses the first unused frame or creates a new one that adds to the pool when finished. Blizzard's way is definitely more sophisticated and made for different scenarios, but if you just need a disposable OnUpdate frame with one piece of data included in the frame, you could try what I did.

Lua Code:
  1. local pool={}
  2. function f.pool(t,i)
  3.     if i then
  4.         pool[i]:SetScript('OnUpdate',nil)
  5.         pool[i].t=nil
  6.         return
  7.     end -- function was called with an index, terminate frame at that index
  8.     for i=1,#pool do
  9.         if pool[i] and not pool[i].t then
  10.             pool[i].t={i=i,t=t}
  11.             return i
  12.         end -- loop through frames to find an unused one and return the index, putting "t" into the frame
  13.     end
  14.     insert(pool,CreateFrame('frame'))
  15.     i=#pool
  16.     pool[i].t={i=i,t=t}
  17.     return i -- no unused frames found, generate a new one and return its index, also putting "t" into the frame
  18. end


An example of usage is the following response to blocked guild invites:

Lua Code:
  1. pool[f.pool((GetCVar('Sound_EnableSFX')))]:SetScript('OnUpdate',function(self)
  2.     SetCVar('Sound_EnableSFX',self.t.t)
  3.     f.pool('',self.t.i)
  4. end)
  5. SetCVar('Sound_EnableSFX','0')

This calls a frame directly from the pool table, while getting the index from f.pool's return and putting the current SFX setting into the "t" key of the frame. Then I turn off SFX. Once the OnUpdate fires a frame later, reset SFX and release the frame using its index stored in the "i" key.

This completely blocks the "level up" sound when someone invites you to a guild.

I'm sure there's a cleaner way to do what I did, but it works for me.
  Reply With Quote