Jump to content

[HELP] Parents and children.


iwalidza

Recommended Posts

  • Moderators

Enough to store parent of elements.
And when you destroy an element, you need to check every other element. (if checked element's parent is equals to destroyed element, you need to delete it too)

On8sFJr.png

For example, if you destroy window.

local dxelements = {}

function destroy(id)
    -- destroy -> id
	
    -- loop trough all other dxelements
    for id2, data in pairs(dxelements) do
    	if data.parent == id then -- checked element's parent equals to destroyed element
        	-- destroy this dxelement too
      		destroy(id2)
    	end
    end
end

Steps:
- Delete window
- Start to check other elements which parent is window. -> Delete tab.
- Start to check other elements which parent is tab. -> Delete button.
- Start to check other elements which parent is button. -> Not found. -> Done.

 

Or you can store childrens of element, and then you don't need to check every other element, because you already know the childrens.

Edited by Patrick
Link to comment
  • Moderators
4 minutes ago, iwalidza said:

then i need insert all childrens in table for parent and for table to all elements

and when i remove the parent need to check for all  childrens of the parent table

Exactly. (and when you remove a children, you need to remove it from parent's table too)

  • Thanks 1
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...