View Single Post
09-01-20, 11:34 PM   #18
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Lua Code:
  1. local frameA = CreateFrame("Frame", "frameA", UIParent)
  2. frameAButton1 = CreateFrame("Button", "frameAButton1", frameA)
  3. frameAButton1:ClearAllPoints()
  4. frameAButton1:SetPoint("CENTER", 0, 0)
  5. frameAButton1:SetSize(40, 40)

frameA is a local
frameAButton1 is a global

I added quotes around the frame names as without them, it would just be the same as using nil unless as variables they had been initialised earlier.

As someone once told me, frames are just special types of tables.

Lua Code:
  1. local frameA = CreateFrame("Frame", "frameA", UIParent)
  2. frameA["Button1"] = CreateFrame("Button", "frameAButton1", frameA)
  3. frameA["Button1"]:ClearAllPoints()
  4. frameA["Button1"]:SetPoint("CENTER", 0, 0)
  5. frameA["Button1"]:SetSize(40, 40)
is the same as the original.

Even:
Lua Code:
  1. local f = CreateFrame("Frame", "frameA", UIParent)
  2. f = CreateFrame("Button", "$parentButton1", f)
  3. f:ClearAllPoints()
  4. f:SetPoint("CENTER", 0, 0)
  5. f:SetSize(40, 40)
Would reduce the number of locals used as you are just re-using the one local. Although doing this you lose the local reference to the top level frame but you could still reference it using the frames name ("frameA") as these are added to the global table (note the use of $parent in the button name)

Lua Code:
  1. frameA:SetSize(100, 100)
  2. frameAButton1:SetText("New Button Label")
This is very much the old XML way of doing things before XML frames had the parentKey attribute.

This being the case,
Code:
local frameA = CreateFrame("Frame", "frameA", UIParent)
local frameA would be fine as a local.

"frameA" would be rubbish as a frame name. Being created as a global there's too much chance of a clash (I forget how it woks but I'm pretty sure first frame with a name is added to the global table, any others with the same name are ignored).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-02-20 at 12:24 AM.
  Reply With Quote