Reply
Thread Tools Display Modes
Unread 11-14-12, 03:20 PM   #1
doublebashhash
A Defias Bandit
Join Date: Nov 2012
Posts: 2
Frame iteration question

Hello, I have a question on frame iteration and LUA scope (I am quite new to LUA). What I want to do is make a function that creates a bunch of child frames that connect to the parent frame and shoves them in a table but I haven't been able to make my attempts work. The reason I'd like to have a table is so that I can then iterate over them easily and change attributes.

Code below:

Code:
 
local frame = createframe('frame', 'frame', UIPARENT)
local frameCache = {}


local function = frameInit(name, x)
--make movable, allow mouse interaction, call makeMiniFrame x number of times

--relevent portion
   for i = 1, x, 1 do
      makeMiniFrame("frame" .. i, frame)
      table.insert(frameCache, "frame" .. i)
   end
end

local makeMiniFrame, otherFrameFunction
do
   makeMiniFrame = function(name, parent)
      local f = CreateFrame('Frame', name, parent)
      otherFrameFunction()
      return f
   end

   otherFrameFunction = function(name)
      if name then
         f = name
      end
      f: --dostuff to frame
   return f
end

--REGISTER EVENTS
Is this the correct way of approaching this or am I completely off base?
doublebashhash is offline   Reply With Quote
Unread 11-14-12, 04:23 PM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,192
Function names are case sensitive so for starters you need
Code:
local frame = CreateFrame("Frame", "myframename", UIParent)
Secondly you can store your frames in a table for easy iteration but frames are tables themselves.
So you could just as well store the references to the children on the parent frame.

Code:
for i=1,5 do
  frame.children = frame.children or {}
  frame.children[i] = CreateFrame("Frame", "child"..i, frame) -- or your custom frame creation function
end

for _,child in ipairs(frame.children) do
  -- manipulate the child frame
end

Last edited by Dridzt : 11-14-12 at 04:30 PM.
Dridzt is offline   Reply With Quote
Unread 11-14-12, 04:42 PM   #3
doublebashhash
A Defias Bandit
Join Date: Nov 2012
Posts: 2
Okay, that seemed to clear up the problem. Thanks!
doublebashhash is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » Frame iteration question

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