WoWInterface (
-   Lua/XML Help (
-   -   Frame iteration question (

doublebashhash 11-14-12 03:20 PM

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:


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)

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

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


Is this the correct way of approaching this or am I completely off base?

Dridzt 11-14-12 04:23 PM

Function names are case sensitive so for starters you need

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.


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

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

doublebashhash 11-14-12 04:42 PM

Okay, that seemed to clear up the problem. Thanks!

All times are GMT -6. The time now is 06:49 PM.

vBulletin © 2015, Jelsoft Enterprises Ltd
©2012 ZAM Network LLC