TextItemGetText: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Remove spaces) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string textItemGetText ( textitem theTextitem ) | string textItemGetText ( textitem theTextitem ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 15: | Line 15: | ||
==Example== | ==Example== | ||
Increment a score display. In real scripts it's of course better to | Increment a score display. In real scripts it's of course better to keep a global 'score' variable which can be incremented directly. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function givePoint ( | function givePoint ( thePlayer ) | ||
local scoretextitem = scoretextitems[player | local scoretextitem = scoretextitems[thePlayer] -- find the score text item that belongs to this player | ||
local score = textItemGetText ( scoretextitem ) | local score = textItemGetText ( scoretextitem ) -- read the text (a score number) | ||
score = tostring(tonumber(score) + 1) | score = tostring(tonumber(score) + 1) -- convert to number, add 1, convert to text | ||
textItemSetText ( scoretextitem, score ) | textItemSetText ( scoretextitem, score ) -- put the new score on the text item | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 27: | Line 27: | ||
==See Also== | ==See Also== | ||
{{Text functions}} | {{Text functions}} | ||
Latest revision as of 21:13, 29 October 2023
This function returns the current text of the specified textitem.
Syntax
string textItemGetText ( textitem theTextitem )
Required Arguments
- theTextitem: A valid textitem.
Returns
Returns a string containing the text if the function was successful, false otherwise.
Example
Increment a score display. In real scripts it's of course better to keep a global 'score' variable which can be incremented directly.
function givePoint ( thePlayer ) local scoretextitem = scoretextitems[thePlayer] -- find the score text item that belongs to this player local score = textItemGetText ( scoretextitem ) -- read the text (a score number) score = tostring(tonumber(score) + 1) -- convert to number, add 1, convert to text textItemSetText ( scoretextitem, score ) -- put the new score on the text item end
See Also
- textCreateDisplay
- textCreateTextItem
- textDestroyDisplay
- textDestroyTextItem
- textDisplayAddObserver
- textDisplayAddText
- textDisplayGetObservers
- textDisplayIsObserver
- textDisplayRemoveObserver
- textDisplayRemoveText
- textItemGetColor
- textItemGetPosition
- textItemGetPriority
- textItemGetScale
- textItemGetText
- textItemSetColor
- textItemSetPosition
- textItemSetPriority
- textItemSetScale
- textItemSetText