TextItemGetColor: Difference between revisions

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


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int int int int textItemGetColor ( textitem textitem )            
int int int int textItemGetColor ( textitem theTextItem )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''textitem:''' The text item you wish to retrieve the colour of.
*'''theTextItem:''' The text item you wish to retrieve the color of.


===Returns===
===Returns===
Returns four integers in RGBA format, with a maximum value of 255 for each. Each stands for ''red'', ''green'', ''blue'', and ''alpha''. Alpha decides transparancy where 255 is opaque and 0 is transparent. ''false'' is returned if the blip is invalid.
Returns four integers in RGBA format, with a maximum value of 255 for each. The values are, in order, ''red'', ''green'', ''blue'', and ''alpha''. Alpha decides transparency where 255 is opaque and 0 is transparent. ''false'' is returned if the text item is invalid.


==Example==  
==Example==  
This example gets the color of a textitem named 'textitem' and if it is green, changes it to blue.
This example gets the color of a text item named 'theTextItem' and if it is green, changes it to blue.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
r,g,b,a = textItemGetColor ( textitem )
local r,g,b,a = textItemGetColor ( theTextItem )           -- get the text color and store it in the variables 'r','g','b' and 'a'
if ( r == 0 ) and ( g == 255 ) and ( b == 0 ) then
if ( r == 0 ) and ( g == 255 ) and ( b == 0 ) then   -- if the color is green
     textItemSetColor ( textitem, 0, 0, 255, 0 )
     textItemSetColor ( theTextItem, 0, 0, 255, 255 ) -- set it to blue
end
end
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 21:15, 29 October 2023

This function allows you to retrieve the color of a text item.

Syntax

int int int int textItemGetColor ( textitem theTextItem )

Required Arguments

  • theTextItem: The text item you wish to retrieve the color of.

Returns

Returns four integers in RGBA format, with a maximum value of 255 for each. The values are, in order, red, green, blue, and alpha. Alpha decides transparency where 255 is opaque and 0 is transparent. false is returned if the text item is invalid.

Example

This example gets the color of a text item named 'theTextItem' and if it is green, changes it to blue.

local r,g,b,a = textItemGetColor ( theTextItem )           -- get the text color and store it in the variables 'r','g','b' and 'a'
if ( r == 0 ) and ( g == 255 ) and ( b == 0 ) then   -- if the color is green
    textItemSetColor ( theTextItem, 0, 0, 255, 255 ) -- set it to blue
end

See Also