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) Any help would be much appreciated, I am finding the online resources to be far too vague for me to piece this together. :confused: |
Code:
function AMget(self) |
works perfect, thank you! Also this teaches me a good deal too. I definitely learn best when I see these things in use. :)
|
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") |
Code:
local skipframes = {} It will also not add anything found in skipframes instead of adding them just to remove them again later. |
Quote:
|
Quote:
(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. |
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 ... |
Quote:
Quote:
Code:
function UnitClass(unit) Code:
local _, class = UnitClass('player') Quote:
|
Code:
for k,v in pairs(com) do as you see, "v" is never used at all, since i use integer indexes the structure of an instance in com is made like : com[UnitGUID] = { 0, 3.5, nil, "", "", nil, nil } |
'for k,v in pairs(mytable) do'
expand the variable names and it comes closer to natural language: 'for key, value in pairs(mytable) do -- stuff with key -- or stuff with value end local vehicles = {"bicycle", "car", "truck"} this table has implicit integer keys it is the equivalent of local vehicles = { [1] = "bicycle", [2] = "car", [3] = "truck", } ipairs works on a subset of lua tables that has sequentially indexed values like above. for index, value in ipairs(vehicles) do print("vehicle:"..value) end The table above is one where the information (the vehicle) is held by the value. ipairs will not work on a table with non-sequential integer keys or other type of keys. for example: local polluters = { ["bicycle"] = false, ["car"] = true, ["truck"] = true, } pairs has to be used here for key, value in pairs(polluters) do if polluters[key] then print("gas masks on") end end |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
Just utilised this myself when I lost my frame whilst trying to figure out the in game frame sizing feature. The frame sizing was given up for the moment as I have a quite fine UI to set the sizes but by just switching my positioning and sizing code to be called after the blizz vars are loaded helped bring my frame back. This is the page I utilised my learning process about loading order from.. http://www.wowwiki.com/Events_that_f...oading_Process |
Quote:
Code:
local frame = CreateFrame("Frame", "AsteroidMinimapButtons", UIParent) Here's the working version without a savedvariables. (Well, sort of working, like I said before the reason I want saved variables is to keep the positions of certain frames that Blizz is overriding like TimeManagerClockButton. Also it loads the function a million times for each Addon, I triesd to add a 'if arg1' deal but I think my SetScript is messy, anyways.) Code:
local AMwait = CreateFrame("Frame","AMWaitFrame", UIParent) |
Quote:
2) "_" is a legal variable name in Lua, most commonly used just to dump any returned values into that aren't needed. 3) You may omit "v" and it should only remember the keys. The function will still return a second value for what's contained in the iterated entry, but Lua will then toss it away since there's no variable to assign it to. The function will always run the same no matter if you assign all return values to a variable or not. A note on the performance of for k,v in pairs(t), all core Lua functions as well as the WoW API are written purely in C. This is extremely fast compared to writing the same function and having it run through the interpreter. As far as iterating through tables, it takes the same amount of time to find the keys as it is to find the associated values. |
Quote:
I have in my SavedVariables table these set of values: Code:
["ptSelf"] = "CENTER", This is how I initially fill the table up after the frame has been created. I have a set of hard coded defaults set up that the addon can fall back onto if problems arise or the user after doing some customising gets messed up and whats to reset everything rofl. Code:
xsf.InitialiseVariables = function(self) Code:
xsf.OnMouseDown = function(self) Code:
xsf.SetAnchor = function(self) Code:
XSF_Data = { 1. Initialise anchor as center of UIParent. 2. Make any necessary changes to anchor if the parent is no longer UIParent. 3. After moving the frame store the anchor settings. 4. After blizzard has finished its own frame movement code ( VARIABLES_LOADED) then SetAnchor to what we last stored it as. I have some other functions set up as well to handle changes on an addon by addon basis as this is all in a file that I plan to make generic to all my addons needing its functionality but this is enough to handle a one on one frame setup. So far it has been working as I expected. You could even validate what GetPoint returns and change it if you want it to store it a different way. Also, you could always add extra points and utilise GetPoint and the other functions to handle all points the frames have and save them all. In my case the anchors being saved are generally single anchors so I haven't needed to expand onto that area yet :D |
Quote:
|
All times are GMT -6. The time now is 10:05 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI