TextItemGetPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Remove spaces)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
{{Server function}}
This function allows retrieval of the position of a text item.
This function allows retrieval of the position of a text item.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float float textItemGetPosition ( textitem textitem )            
float float textItemGetPosition ( textitem theTextItem )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''textitem:''' The textitem you wish to retrieve the position of
*'''theTextItem:''' The textitem you wish to retrieve the position of


===Returns===
===Returns===
Line 16: Line 17:
This example creates a text item 'myTextItem' only if the text item 'otherTextItem' is not in the same position, to prevent overlap.  If it is in the same position, then it moves it down.
This example creates a text item 'myTextItem' only if the text item 'otherTextItem' is not in the same position, to prevent overlap.  If it is in the same position, then it moves it down.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
myDisplay = textCreateDisplay () --created display
function MyTestTextFunction ()
textDisplayAddObserver ( myDisplay, myPlayer ) --made display visible to player
myDisplay = textCreateDisplay ( )                   -- create a text display
x,y = textItemGetPosition ( otherTextItem ) --get the position of 'otherTextItem'
textDisplayAddObserver ( myDisplay, myPlayer )     -- make it visible to the player
if ( x ~= 0.5 ) and ( y ~= 0.5 ) then --if the x and y of the text item are not in the middle
x,y = textItemGetPosition ( otherTextItem )         -- get the position of 'otherTextItem'
    myTextItem = textCreateTextItem ( "Hello world!", 0.5, 0.5 ) --create a new item for the display in the middle saying "Hello world"
if ( x == 0.5 ) and ( y == 0.5 ) then               -- if the x and y of the text item are in the middle
    textDisplayAddText ( myDisplay, myTextItem ) --and add it to the text display
     textItemSetPosition ( otherTextItem, 0.5, 0.6 ) -- move otherTextItem down
else --otherwise
end
     textItemSetPosition ( otherTextItem, 0.5, 0.6 ) --move the otherTextItem down  
myTextItem = textCreateTextItem ( "Hello world!", 0.5, 0.5 ) -- create a new textitem in the middle saying "Hello world"
    myTextItem = textCreateTextItem ( "Hello world!", 0.5, 0.5 ) --and create a new item for the display in the middle saying "Hello world"
textDisplayAddText ( myDisplay, myTextItem )                 -- and add it to the text display
    textDisplayAddText ( myDisplay, myTextItem ) --then and add it to the text display
end
end
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 21:14, 29 October 2023

This function allows retrieval of the position of a text item.

Syntax

float float textItemGetPosition ( textitem theTextItem )

Required Arguments

  • theTextItem: The textitem you wish to retrieve the position of

Returns

Returns two floats of the x and y position on the screen, where the maximum value is 1.0.

Example

This example creates a text item 'myTextItem' only if the text item 'otherTextItem' is not in the same position, to prevent overlap. If it is in the same position, then it moves it down.

function MyTestTextFunction ()
myDisplay = textCreateDisplay ( )                   -- create a text display
textDisplayAddObserver ( myDisplay, myPlayer )      -- make it visible to the player
x,y = textItemGetPosition ( otherTextItem )         -- get the position of 'otherTextItem'
if ( x == 0.5 ) and ( y == 0.5 ) then               -- if the x and y of the text item are in the middle
    textItemSetPosition ( otherTextItem, 0.5, 0.6 ) -- move otherTextItem down
end 
myTextItem = textCreateTextItem ( "Hello world!", 0.5, 0.5 ) -- create a new textitem in the middle saying "Hello world"
textDisplayAddText ( myDisplay, myTextItem )                 -- and add it to the text display
end

See Also