Thread Tools Display Modes
04-21-10, 02:34 PM   #1
eddiemars
A Cyclonian
 
eddiemars's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 43
Beginner confused with table lua and layout-local frames.

Edit: Scroll down a couple comments if you wish to see my layout-local frame question, my frame question having been answered so speedily.

Hello. While I am sure this is a very simple problem I am having confusions on how to execute this. The table I am wanting is essentially a list of Minimap Children (though I want to remove some items), and I have included code in the lua to put this into my chat frame to make sure it is working. Okay easy:
Code:
function AMget(self)
	local kiddies = { Minimap:GetChildren() }
	for _, frame in pairs(kiddies) do
		DEFAULT_CHAT_FRAME:AddMessage( frame:GetName() ); 
	end
end
This works fine. Great, now I know everything that uses Minimap as a parent. I then see however, that a couple things use it as a parent that I do not want in my table. MinimapPing and MinimapBackdrop. So now I want to figure out a way to have my 'kiddies' table say everything it did before, minus those two things I mentioned. So I researched into 'tremove' and I have fiddled with that but I am very confused with two things: how would I assign tremove with a position when all I have is a name (a name which might change position depending on what is loaded in game), and how do I impliment tremove(table, position) into the code?

Any help would be much appreciated, I am finding the online resources to be far too vague for me to piece this together.
__________________
MAGICAL CRAWDAD APPROVED:

Last edited by eddiemars : 04-21-10 at 06:13 PM.
  Reply With Quote
04-21-10, 03:00 PM   #2
Xus
A Fallenroot Satyr
 
Xus's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 25
Code:
function AMget(self)
	local kiddies, i = { Minimap:GetChildren() }, 1;
	DEFAULT_CHAT_FRAME:AddMessage( "before:" );
	for _, frame in ipairs(kiddies) do
		DEFAULT_CHAT_FRAME:AddMessage( frame:GetName() ); 
	end
	
	--remove MinimapPing and MinimapBackdrop
	while i <= #kiddies do
		if kiddies[i]:GetName() == "MinimapPing" or kiddies[i]:GetName() == "MinimapBackdrop" then
			tremove(kiddies,i);
		else
			i=i+1;
		end
	end
	
	-- do other stuff!
	DEFAULT_CHAT_FRAME:AddMessage( "after:" ); 
	for _, frame in ipairs(kiddies) do
		DEFAULT_CHAT_FRAME:AddMessage( frame:GetName() ); 
	end
end
this is not the uber-most-efficient way, but it works fine
  Reply With Quote
04-21-10, 03:30 PM   #3
eddiemars
A Cyclonian
 
eddiemars's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 43
works perfect, thank you! Also this teaches me a good deal too. I definitely learn best when I see these things in use.
__________________
MAGICAL CRAWDAD APPROVED:
  Reply With Quote
04-21-10, 06:10 PM   #4
eddiemars
A Cyclonian
 
eddiemars's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 43
Another question, since I don't feel like thread spamming I'll just tack it on here, and if no one sees it that's okay.

Okay so I've been playing around a lot with various frames doing:
Code:
frame:RegisterForDrag("LeftButton")
frame:SetClampedToScreen(true)
frame:SetMovable(true)
frame:SetScript("OnDragStart", function(self) if IsAltKeyDown() then self:StartMoving() end end)
frame:SetScript("OnDragStop", function(self) if IsAltKeyDown() then self:StopMovingOrSizing() end end)
I find it works for just about every frame indeed. BUT, when I /reload, it only saves the position of a couple. MinimapMailFrame for example, that gets saved perfectly. TimeManagerClockButton however, it can be moved yes, but goes back to it's original position each time after a /reload. I have also tried calling frame:ClearAllPoints() (also I tried frame:SetUserPlaced(true), this just makes errors) but it seems to make no difference at all. Does anyone know either why this happens to only some frames, or a way to stop this resetting from happening?
__________________
MAGICAL CRAWDAD APPROVED:

Last edited by eddiemars : 04-21-10 at 06:19 PM.
  Reply With Quote
04-21-10, 09:11 PM   #5
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by eddiemars View Post
Does anyone know either why this happens to only some frames, or a way to stop this resetting from happening?
http://www.wowwiki.com/API_Frame_SetUserPlaced

(or alternatively, save the position(s) in a PLAYER_LEAVING_WORLD event handler and restore on VARIABLES_LOADED or similar.)

Edit: I missed that you were talking about Bliz frames. A lot of them try to make sure they're in the "correct" place, and you'd have to override that. There are a number of other threads about doing that.

Last edited by Akryn : 04-21-10 at 09:14 PM.
  Reply With Quote
04-22-10, 03:57 AM   #6
Sideshow
A Flamescale Wyrmkin
 
Sideshow's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 103
something i still did not read anywere:

what's the difference between pairs and ipairs ?
what is this "_" thing ?

would be great to know

also, in my addon, i use a standard for k,v in pairs(mytable) do
but i don't even use the v in the script .... I reckon it takes a "long" time for the cpu to find the v though ...
  Reply With Quote
04-22-10, 10:29 AM   #7
eddiemars
A Cyclonian
 
eddiemars's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 43
Originally Posted by Akryn View Post
(or alternatively, save the position(s) in a PLAYER_LEAVING_WORLD event handler and restore on VARIABLES_LOADED or similar.)

Edit: I missed that you were talking about Bliz frames. A lot of them try to make sure they're in the "correct" place, and you'd have to override that. There are a number of other threads about doing that.
Spent a while searching for threads about it but I came up nil. You think if I just set up a saved variables it will override the correcting of blizz's frames?
__________________
MAGICAL CRAWDAD APPROVED:
  Reply With Quote
04-21-10, 06:14 PM   #8
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Code:
local skipframes = {}
skipframes["MinimapPing"] = true
skipframes["MinimapBackdrop"] = true

local children = {}

function GetChildrenTree(Frame) 
  if Frame:GetChildren() then
    for _,child in pairs({Frame:GetChildren()}) do
      if not skipframes[child:GetName()] then
        tinsert(children,child);
      end
      GetChildrenTree(child);
    end 
  end
end

GetChildrenTree(Minimap)
This is a recursive function so it will call itself until it gets all the Minimap children (not just the first level ones).
It will also not add anything found in skipframes instead of adding them
just to remove them again later.
  Reply With Quote
04-21-10, 06:59 PM   #9
eddiemars
A Cyclonian
 
eddiemars's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 43
Originally Posted by Dridzt View Post
This is a recursive function so it will call itself until it gets all the Minimap children (not just the first level ones).
It will also not add anything found in skipframes instead of adding them
just to remove them again later.
Oh this is quite nice looking indeed, thank you.
__________________
MAGICAL CRAWDAD APPROVED:
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Beginner confused with table lua.


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