DgsSetParent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Server client function}} __NOTOC__ This function is used to determine the parent of an ''element''. ==Syntax== <syntaxhighlight lang="lua"> element getElementParent ( elem...")
 
m (DGS (OOP Syntax)/(Template Organization) Mission)
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Client function}}
__NOTOC__
__NOTOC__  
This function is used to determine the parent of an ''element''.
This function is used for setting a DGS element as the parent of another DGS element.
 
{{Note|DGS elements are always destroyed when the resource that created them is stopped.}}
{{Note|dgsSetParent only works with DGS elements.}}
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element getElementParent ( element theElement )   
bool dgsSetParent( element theElement, element parent )   
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[element]]:getParent|parent|setElementParent}}
{{DGS/OOP||DGSElement:setParent||parent|dgsGetParent||}}


===Required Arguments===  
===Required Arguments===  
*'''theElement:''' The child of the parent element you want returned.
*'''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===
This returns the parent as an ''element''. It returns ''false'' if ''theElement'' is invalid, or is the root node.
Returns ''true'' if both [[element]]s are valid, ''false'' otherwise.
 
==Example==
<section name="Server" class="server" show="true">
Consider the following map file:
<syntaxhighlight lang="xml">
<spawngroup id="red">
  <spawnpoint id="spawnpoint_0" posX="2507.8715820313" posY="2772.6071777344" posZ="10.8203125" rot="270" skin="285"/>
  <spawnpoint id="spawnpoint_1" posX="2508.060546875" posY="2780.3647460938" posZ="10.8203125" rot="270" skin="285"/>
</spawngroup>
<spawngroup id="blue">
  <spawnpoint id="spawnpoint_5" posX="2733.4184570313" posY="2753.1276855469" posZ="10.8203125" rot="90" skin="124"/>
  <spawnpoint id="spawnpoint_6" posX="2733.5258789063" posY="2748.1110839844" posZ="10.8203125" rot="90" skin="125"/>
</spawngroup>
</syntaxhighlight>


This function determines a spawnpoint's parent element, and announces its ID:
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function spawnpointUse ( thePlayer )             -- this function gets called whenever a spawnpoint is used
DGS = exports.dgs
  theSpawnGroup = getElementParent ( source )   -- get the spawnpoint's parent element
parent = DGS:dgsCreateWindow( 500, 500, 300, 300, "test window", false ) -- create a window
  -- announce the parent's ID and the player who spawned there:
label = DGS:dgsCreateLabel( 0, 0, 300, 20, "test label", false ) -- create a label that its parent is the screen
  outputChatBox ( getPlayerName ( thePlayer ) .. " spawned at team " .. getElementID ( theSpawnGroup ) .. "'s spawnpoint." )
DGS:dgsSetParent(label, parent) -- set the window as the parent of the label
  -- Example output: "Joe spawned at team blue's spawnpoint."
end
addEventHandler ( "onSpawnpointUse", root, spawnpointUse )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{element_functions}}
 
===<span style="color:#eb3f00;text-shadow:0.05em 0.05em 0.2em #00000099;">General Functions</span>===
{{DGS General Functions}}
 
===<span style="color:#eb3f00;text-shadow:0.05em 0.05em 0.2em #00000099;">General Events</span>===
{{DGS Events/General}}

Latest revision as of 18:39, 16 April 2021

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

[[{{{image}}}|link=|]] Note: DGS elements are always destroyed when the resource that created them is stopped.
[[{{{image}}}|link=|]] Note: dgsSetParent only works with DGS elements.

Syntax

bool dgsSetParent( element theElement, element parent )  

DGS OOP Syntax Help! I don't understand this!

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

DGS = exports.dgs
parent = DGS:dgsCreateWindow( 500, 500, 300, 300, "test window", false ) -- create a window
label = DGS:dgsCreateLabel( 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

General Functions

General Events