SetElementID: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 17: Line 17:
==Example==  
==Example==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Add example..
local players = getElementsByType( "player" ) -- Get a table of all players.
 
for i=1,#players do
  setElementID( players[i], "player" .. tostring(i) ) -- Loop the table and change the element IDs to 'player1', 'player2', 'player3'...
end
-- COULD ALSO BE --
for i=1,#players do
  setElementID( players[i], getPlayerName( players[i] ) -- This will change the element ID to the players name.
end
 
 
for i=1,#players do
  outputDebugString( "Player[" .. i .. "] = " .. getElementID( players[i] ) ) -- Output the new element IDs to debugstring.
end
</syntaxhighlight>
</syntaxhighlight>



Revision as of 19:45, 13 July 2012

This function sets the ID of an element to a string. This can be anything from an identifying number, to a name.

Syntax

bool setElementID ( element theElement, string name ) 

Required Arguments

  • theElement: The element you want to set the ID of.
  • name: The new ID for theElement.

Returns

This returns true if successful. It will return false if theElement is invalid, or does not exist, or if name is invalid, or is not a string.

Example

local players = getElementsByType( "player" ) -- Get a table of all players.

for i=1,#players do
   setElementID( players[i], "player" .. tostring(i) ) -- Loop the table and change the element IDs to 'player1', 'player2', 'player3'...
end
-- COULD ALSO BE --
for i=1,#players do
   setElementID( players[i], getPlayerName( players[i] ) -- This will change the element ID to the players name.
end


for i=1,#players do
   outputDebugString( "Player[" .. i .. "] = " .. getElementID( players[i] ) ) -- Output the new element IDs to debugstring.
end

See Also