WoWInterface

WoWInterface (http://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (http://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Frame iteration question (http://www.wowinterface.com/forums/showthread.php?t=45149)

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:

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?

Dridzt 11-14-12 04:23 PM

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


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 09:29 PM.

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