Having trouble understanding looped frame creation
Basically what I'm trying to do is learn how to do various things by creating UI elements that I desire in my personal gameplay. I've learned a lot, but there's a lot left to go. I want to create several extra action buttons along the bottom side of my minimap, squished tightly together. I can create one button successfully, using SecureActionButtonTemplate and SecureHandlerDragTemplate so that the buttons can have basically anything dragged onto/off of them at will.
But when I try to loop to create multiple buttons it does not work, saying that the local variable I'm using to store the array is nil (which it should be, as I haven't defined any buttons yet) The question is how am I supposed to handle this?? Thanks for the help Code:
local numMapButtons = math.floor(Minimap:GetWidth() / 20) I'm an idiot, I need to declare the variable as an array: local mapButton ={}; is sufficient to make that happen. From there I've got other problems, but this makes more sense now. I obviously need to change the way I am using SetPoint now that I've progressed forward. PROGRESS THOUGH! |
That's the issue. The local variable is nil. It needs to be a table before you assign any indexes.
You also need to create a separate frame for each button, but that top line in the loop will reuse the same frame over and over again, only creating one button that will either keep moving over 5 pixels or error trying to create a second button because you can't anchor a frame to itself. Change these two lines: Lua Code:
To these: Lua Code:
This makes mapButton an empty table, ready to accept the indexes you're trying to assign, and properly creates a separate frame for each button with the index appended to the global name so they can all coexist. |
Just an example of how I do it in my addons. Not saying it's right. But using a class and a loop to create some frames. Should be able to copy this into an existing addon and see the effect.
Code:
TestAddon = {} |
FANTASTIC.
This makes SO MUCH more sense now. I knew it had to be something small that I was missing with the way frame creation is handled within the WoW API and the way variable typing happens in lua. Holy cow that is such a relief lol. Now it's just time to work on the positioning via setpoint but that's a different battle, and much simpler. |
All times are GMT -6. The time now is 07:53 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI