DgsSetParent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 18: Line 18:
==Example==  
==Example==  
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
This example sets the parent of each spawnpoint to a dummy element:
This example shows how it works:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
dummyElem = createElement ( "spawngroup", "Group of spawn points" ) -- create a dummy element
DGS = exports.dgs
local spawnpoints = getElementsByType ( "spawnpoint" ) -- get a table of spawn point elements
parent = DGS:dgsDxCreateWindow( 500, 500, 300, 300, "test window", false ) -- create a window
for k,v in ipairs (spawnpoints) do -- loop through the table of spawn points
label = DGS:dgsDxCreateLabel( 0, 0, 300, 20, "test label", false ) -- create a label that its parent is the screen
  setElementParent ( v, dummyElem ) -- set the dummy element as the parent of the spawn point
DGS:dgsSetParent(label, parent) -- set the window as the parent of the label
end
-- all of the spawn points are now children of 'dummyElem'
</syntaxhighlight>
</syntaxhighlight>



Revision as of 09:21, 27 June 2017

This function is used for setting a DGS element as the parent of another DGS element.

[[{{{image}}}|link=|]] Note: This function does not change when an element will be destroyed - DGS elements are always destroyed when the resource that created them is stopped.
[[{{{image}}}|link=|]] Note: dgsSetParent only works to DGS elements.

Syntax

bool dgsSetParent( element theElement, element parent )  

Required Arguments

  • theElement: The dgs element that you wish to set the parent of.
  • parent: The dgs element you wish to be the parent of theElement.

Returns

Returns true if both elements are valid, false otherwise.

Example

Click to collapse [-]
Client

This example shows how it works:

DGS = exports.dgs
parent = DGS:dgsDxCreateWindow( 500, 500, 300, 300, "test window", false ) -- create a window
label = DGS:dgsDxCreateLabel( 0, 0, 300, 20, "test label", false ) -- create a label that its parent is the screen
DGS:dgsSetParent(label, parent) -- set the window as the parent of the label

See Also

Shared