GetElementParent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(Fix oop syntax)
 
(14 intermediate revisions by 10 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
__NOTOC__
This function is used to determine the parent of an ''element''.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element getElementParent ( element element )   
element getElementParent ( element theElement )   
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[element]]:getParent|parent|setElementParent}}


===Required Arguments===  
===Required Arguments===  
*'''argumentName:''' description
*'''theElement:''' The child of the parent element you want returned.


===Optional Arguments===  
===Returns===
{{OptionalArg}}
This returns the parent as an ''element''. It returns ''false'' if ''theElement'' is invalid, or is the root node.
*'''argumentName2:''' descriptiona
*'''argumentName3:''' description


===Returns===
==Example==
Returns ''true'' if blah, ''false'' otherwise.
<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>


==Example==
This function determines a spawnpoint's parent element, and announces its ID:
This example does...
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function spawnpointUse ( thePlayer )            -- this function gets called whenever a spawnpoint is used
blabhalbalhb --abababa
  theSpawnGroup = getElementParent ( source )  -- get the spawnpoint's parent element
--This line does this...
  -- announce the parent's ID and the player who spawned there:
mooo
  outputChatBox ( getPlayerName ( thePlayer ) .. " spawned at team " .. getElementID ( theSpawnGroup ) .. "'s spawnpoint." )
  -- Example output: "Joe spawned at team blue's spawnpoint."
end
addEventHandler ( "onSpawnpointUse", root, spawnpointUse )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{FunctionArea_Functions}}
{{element_functions}}

Latest revision as of 13:51, 6 August 2016

This function is used to determine the parent of an element.

Syntax

element getElementParent ( element theElement )  

OOP Syntax Help! I don't understand this!

Method: element:getParent(...)
Variable: .parent
Counterpart: setElementParent


Required Arguments

  • theElement: The child of the parent element you want returned.

Returns

This returns the parent as an element. It returns false if theElement is invalid, or is the root node.

Example

Click to collapse [-]
Server

Consider the following map file:

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

This function determines a spawnpoint's parent element, and announces its ID:

function spawnpointUse ( thePlayer )             -- this function gets called whenever a spawnpoint is used
   theSpawnGroup = getElementParent ( source )   -- get the spawnpoint's parent element
   -- announce the parent's ID and the player who spawned there:
   outputChatBox ( getPlayerName ( thePlayer ) .. " spawned at team " .. getElementID ( theSpawnGroup ) .. "'s spawnpoint." )
   -- Example output: "Joe spawned at team blue's spawnpoint."
end
addEventHandler ( "onSpawnpointUse", root, spawnpointUse )

See Also

Shared