Quantcast Can you name a frame AFTER it's been created? - WoWInterface
Thread Tools Display Modes
08-16-19, 03:28 PM   #1
aallkkaa
A Black Drake
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 89
Can you name a frame AFTER it's been created?

I'm basically looking for a counterpart to frame:GetName()

I tried the following, which does not work:
Lua Code:
  1. frame = CreateFrame("Frame");
  2. frame:SetAttribute:"Name", "SomeName");

In cas you're wondering, I want to reuse a frame I use to listen to PLAYER_LOGIN as one of the configuration-dependent frames to create afterwards.
  Reply With Quote
08-16-19, 07:37 PM   #2
kurapica.igas
A Flamescale Wyrmkin
Join Date: Aug 2011
Posts: 113
No, you can't, there is no SetName method. But normally there is no need to give a frame name unless it's a secure one.

If you need access it in _G, just use _G[name] = frame, it's not a good practice, since you always can save it in your own addon.

Or you can create a parent-child system that the child's name is saved in its parent so you can access any frames in a root frame like `root.Form.Label:SetText(xx)`, it's the name of your own system, so you can change them to whatever you want.
  Reply With Quote
08-17-19, 08:38 AM   #3
aallkkaa
A Black Drake
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 89
Thank you for the awesome tips, kurapica.igas!

_G[name] = frame seems to be more what I wanted. But the parent-child system looks interesting. I'll play around with those.
  Reply With Quote
08-17-19, 08:48 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,122
The _G[] isn't required unless you're looking up the frame name as a string.

Code:
local f = Createframe("Frame", "FizzleFrameX", UIParent)
FizzleFrameX.Texture = FizzleFrameX:CreatTexture()
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
08-17-19, 10:57 AM   #5
aallkkaa
A Black Drake
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 89
Originally Posted by Fizzlemizz View Post
The _G[] isn't required unless you're looking up the frame name as a string.

Code:
local f = Createframe("Frame", "FizzleFrameX", UIParent)
FizzleFrameX.Texture = FizzleFrameX:CreateTexture()
(fixed a typo for you)
I'm not sure I understand what you said. I mean, in the example you gave, you could equally do:
Lua Code:
  1. local f = Createframe("Frame", "FizzleFrameX", UIParent)
  2. f.Texture = f:CreateTexture()
In any case, me wanting the frame to be globally accessible doesn't have anything to do with the addon's normal operation. It's a personal addon, whose frames' positions and geometries I may sometimes change in the code (which I haven't in a long time, but that's beyond the point). Instead of coding the changes in the addon and then reloading the UI to check it out, I like to do /run frame:SetPoint(...), /run frame:SetWidth(...), etc, right there on the console. That's it.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Can you name a frame AFTER it's been created?

Thread Tools
Display Modes

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