StefanAlmighty Posted June 9, 2016 Share Posted June 9, 2016 Okay so I'm working on a dxGUI system and the GUI's children is stored in tables in the element data. For example if you made an edit box on a window it would be stored in the getElementData(window, "children") which is a table. In my system children can have children can have children etc, I want a quick system which deletes the every element within the original window. I'm not sure how. I've started with this: function dxDestroyElement(element) -- destroys an entire tree of elements local children = getElementData(element, "children") if getElementData(element, "children") then for i, v in ipairs(children) do destroyElement(v) end end destroyElement(element) end This only destroys the main element and it's children. The 'grand-children' etc aren't destroyed as it'd be a huge chunk of code. Is there a way of constantly looping through the children destroying each one? Link to comment
KariiiM Posted June 9, 2016 Share Posted June 9, 2016 function dxDestroyElement(element) -- destroys an entire tree of elements if not isElement (element) then return end local children = getElementData(element, "children") if not children then return end for i, v in ipairs(children) do if isElement (v) then destroyElement(v) v = nil end end end destroyElement(element) end Link to comment
Castillo Posted June 9, 2016 Share Posted June 9, 2016 Why don't you just use setElementParent? this way, if you delete the parent, the children will be deleted aswell, with no extra code. Link to comment
StefanAlmighty Posted June 9, 2016 Author Share Posted June 9, 2016 Solidsnake because of these notes: Thanks Karim, I'll try that now. PS: Karim will that work for children of children of children? Link to comment
StefanAlmighty Posted June 9, 2016 Author Share Posted June 9, 2016 Didn't destroy all the children of the children elements. I need a loop that loops through every possible child element and destroys them, but not sure how. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now