View Single Post
08-23-17, 04:14 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,333
Long story short, the variables don't actually store the table itself. They store a pointer that tells Lua where the table data is. This means when the Ace profile changes, dbsetting remains pointing to the old table. You need to call MyAddon:SetupDrag() again to update, but there is already an inherent problem in doing so. You're wasting resources dynamically creating new functions every time you call it. To prevent this, you should create static versions of them as upvalues so they don't get recreated constantly. To handle saving their positions, each frame called in the code below will store a reference to its own profile table. Again, you still need to call MyAddon:SetupDrag() each time the profile changes to update these references.

Lua Code:
  1. local function Frame_OnMouseDown(self)
  2.     if not self.isMoving then  
  3.         self:StartMoving()
  4.         self.isMoving = true
  5.     end
  6. end
  7.  
  8. local function Frame_OnMouseUp(self)
  9.     if self.isMoving then
  10.         self:StopMovingOrSizing()
  11.         self.isMoving = false
  12.  
  13.         self.settings[1], self.settings[2], self.settings[3], self.settings[4], self.settings[5] = self:GetPoint(1)
  14.     end
  15. end
  16.  
  17. function MyAddon:SetupDrag(frame, settings)
  18.     frame.settings=settings
  19.     frame:SetScript("OnMouseDown", Frame_OnMouseDown)
  20.     frame:SetScript("OnMouseUp", Frame_OnMouseUp)
  21. end

PS: frame:GetPoint() needs an index saying which point you want. I'm surprised this hasn't thrown an error.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote