Jump to content

Looping and deleting all elements


Recommended Posts

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...