Skip to content
Thomas edited this page Aug 24, 2020 · 1 revision

Parent and child system

To some people, not very familiar with programming analogies, a "Parent and child system" mind sound very weird. However, this page explains how the system works.

When you make a ui, you have a whole ton of loose components: multiple buttons, sliders, checkboxes, etc.. Now you, the user, want to position all those objects in a neat and ordered way. Many user interfaces use panels and windows to put objects "inside of". Consider the following strategy game example:

*Excuse the crudely drawn example*

What you can see in the example above is that there is a bar on the bottom. Inside the bar there is a minimap and some text on the left side. On the right side, there is another panel. Inside that panel there are three resource progress bars. On the top right there is a floating window. Inside the window there is a list of units.

Notice the constant use of the word inside in the paragraph above. There is a certain structure to our ui. We can depict our picture in a tree or bullet list like so:

  • ui root
    • bottom panel
      • strategy text
      • minimap
      • resource panel
        • food resource bar
        • wood resource bar
        • stone resource bar
    • floating window
      • resource list

Now a real hierarchy starts to exist. Now for the termology. When we take an object, lets say the "strategy text" and look at it we see that it is inside the bottom panel. We say the the bottom panel is the parent of the strategy text. We can also say this the other way around. The strategy text is the child of the bottom panel. Note that the minimap is also a child of the bottom panel as is the resource panel. The food resource bar is not a child of the bottom panel. Instead, the food resource bar is the child of the resource panel. The resource panel has 3 children.

Compare this to a family tree:

  • your grandma
    • your mother
      • your sister
      • your brother
      • you
        • your daughter
        • your son
        • another daughter
    • your aunt
      • your niece

This looks a lot like the other tree we had for our strategy game. That is why the "parent-child" analogy is used. The only notable difference is that in a family, you usually have two parents. In uiZ, you can only have a single parent.

In uiZ, you will have to use function to manipulate your "family tree" in your UI to give structure to it. For this, you can use these functions:

  • uiz_setParent(instanceid, newParent): Changes the parent of the instance to the given newParent. If the object was already assigned a parent, then the previously assigned parent is no longer the parent of the given instance.

    • instanceid: The instanceid of the object you want to be the child of the parent.
    • newParent: The instance id of an object that should be the new parent of the given instance. The instanceid will now become the child of the newParent.
  • parent = uiz_getParent(instanceid):

    • parent: The parent of the given instanceid.
    • instanceid: The uiz object you want to know the parent of.
  • uiz_children_adopt(from, to): Transfers all children from argument0 to argument1. Useful if you want to destroy an object, but don't want all the children to have uiZ_obj_controller as a parent.

    • from: From what object the children should be transferred. Needs to be a game maker instance id.
    • to: To what object the children should be transferred. Needs to be a game maker instance id.
  • hasChild = uiz_hasChild(instanceid, child): Checks if the given child exists directly inside the instanceid.

    • hasChild: A boolean value on whether the given child has been found inside the instanceid.
    • instanceid: The parent who's children needs to be searched for the correct child.
    • child: The instance id of an uiZ object for which you are searching.
  • hasChild = uiz_hasChild(instanceid, child): Checks if the given child exists inside the instanceid and searches recursively down the entire object tree to find the child. This mean that the grandchildren and the grandchildren's children are also searched for the specific child.

    • hasChild: A boolean value on whether the given child has been found inside the tree of the instanceid.
    • instanceid: The parent below which this function needs to look for the specific child.
    • child: The instance id of an uiZ object for which you are searching.
  • hasParent = uiz_hasParent(instanceid, findParent): Checks whether the given parent is the parent of the given instanceid. hasParent: Whether the given parent is the parent of the given instanceid.

    • instanceid: The child for which to check for the parent.
    • findParent: What parent this function has to check for.
  • hasParent = uiz_hasParent_inChain(instanceid, findParent): Checks whether the given parent is the parent of the given instanceid. Recursively checks the objects parent and the grandparent, and the grandparent's parent, etc... hasParent: Whether the given parent is the parent of the given instanceid.

    • instanceid: The child for which to check for the parent.
    • findParent: What parent this function has to check for.
  • children = uiz_getChildren(instanceid): Returns a ds list of children for the given instanceid. DO NOT EDIT THE DS LIST. Doing so could result in a broken family tree, or broken depth sorting.

    • children: A ds list of children for the given instanceid. DO NOT EDIT THE DS LIST.
    • instanceid: For which parent this function should get the children list from.

Wiki pages

🏑Home / General
πŸ“ƒTutorials
πŸ‘ͺ Parent
↕️ Positioning
πŸ›  Fixing & Updating
πŸ• Depth
πŸ“ƒ Templates and Examples
πŸŒ† Background
πŸ“‡ Structures
🎈 Objects

obj_uiZ_3waybutton
obj_uiZ_button
obj_uiZ_checkbox
obj_uiZ_clock
obj_uiZ_colorbox
obj_uiZ_cover
obj_uiZ_drawdslist obj_uiZ_dropdown
obj_uiZ_easybutton
obj_uiZ_frame
obj_uiZ_framescrollbar
obj_uiZ_functionbar
obj_uiZ_gradientsquare
obj_uiZ_gradientroundrect
obj_uiZ_gridlist
obj_uiZ_huesquare
obj_uiZ_loadingbar
obj_uiZ_loadingcircle
obj_uiZ_menubutton
obj_uiZ_mousemenu
obj_uiZ_radiobox
obj_uiZ_rotator
obj_uiZ_slider
obj_uiZ_scrollbar
obj_uiZ_slider_2col
obj_uiZ_slickslider
obj_uiZ_slideframe
obj_uiZ_sprbutton
obj_uiZ_spriteanimationbutton
obj_uiZ_spritecounter
obj_uiZ_stringbox
obj_uiZ_sliderstruct
obj_uiZ_surfacecanvas
obj_uiZ_sprite
obj_uiZ_square
obj_uiZ_squarebutton
obj_uiZ_swipicon
obj_uiZ_switch
obj_uiZ_tabslider
obj_uiZ_tabs
obj_uiZ_treelist
obj_uiZ_text
obj_uiZ_text_background
obj_uiZ_textarea
obj_uiZ_valuebox


🎈 Your own objects
🚫 Destroy
🐭 Mouse
πŸ’» Windows (uiz)
🌌 Animations
❓ General
πŸ“’ Numbers
πŸ“’ Strings
✏️ Draw
🚩 Popup
πŸ“‚ Files
πŸ’» Windows (os)

Clone this wiki locally