Remove a Frame element with LUA
hi guys
i want to create a frame that shows your main bag's content with icons too... so when i open up my addon frame the LUA dynamically draws a frame and draws the CURRENT content of my bag into... is it possible to remove/delete/clear frames, textures and fontstrings ( xml elements ) with LUA somethings like Frame:Delete ? thanks for any replies |
No, this is not possible. Nor is it possible to give them to the Lua garbage collection facility. What you need to do is create these things once and re-use them as they're needed.
|
thanks for reply
and how to do that? can you give me some little example in LUA? how can i reuse the elements? |
lua Code:
Something like that as a very basic example |
thank you so much :banana:
|
cant you for example simply write frame=nil?
dont shoot me ^^ -- |
That nils the reference to the frame, and maybe its properties, but the actual frame object is still in memory.
|
Quote:
*BLAM!* |
But you can reduce the memory allocation by stripping the variable of it's data with f={}.
|
Quote:
|
And what about table.wipe(f) ?
|
That does nothing for frames but clear their table members. The frame itself still exists, and will always exist until the UI is reloaded or you re-start WoW. Tables CAN be garbage-collected. Frames, though they are a special form of table, CANNOT.
|
Quote:
lua Code:
|
No - that requires that you have a frame pointer for restoreframe(), which at that point isn't really possible without breaking the illusion that the frame has been "deleted". You would use this, instead:
Code:
local AcquireFrame, ReleaseFrame |
Quote:
|
Quote:
This code gives you a way to say "I no longer need this frame. Make it go away." while still giving you a way to re-claim it later if it's needed, or a create a new one if there are none currently in the cache. If you want to be sure you're dealing with the same frame every time, why in the hell would you "delete" it and then "reclaim" it? Just hide the damn thing and unregister its events, then un-hide it when you need it to be available again. Also, setting an OnEvent script like this: Code:
frame:SetScript("OnEvent", function() end) Code:
frame:UnregisterEvent(PLAYER_REGEN_DISABLED) Code:
frame:SetScript("OnEvent", nil) |
I see, but still I think you should clean up the frame a little bit more, since once you'd want to reuse a frame you get all the rubbish hooked to it. What about this? I'm planning to release it as a lib.
LUA Code:
|
I do not see any benefit in having this exist as a library - the caching code is simple and small enough to be included directly within the AddOn. Also, indiscriminately setting all scripts to nil and removing the global name can cause an assortment of issues. If you're making a named frame, or setting scripts to it, you're generally going to want to keep it around so removing either makes no sense. Also, you cannot determine the intent of such a library's users - they may want the ability to safely add and remove frames for a frame factory, but not do all of the things you are doing.
The code I pasted here is ripped from my own LibQTip library, which manages its OWN frames since it knows all the attributes which are set on them. A general-purpose library that attempts to do such a thing will ultimately fail. AddOn A does this: Code:
frame.this_is_awesome = function(self, arg1) DoStuff() end |
Quote:
|
That's why remembering that there's no such thing as a magic bullet is so important. :D
|
All times are GMT -6. The time now is 11:46 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI