Skip to content

UText and Functions

Alec Sears edited this page Jan 23, 2014 · 1 revision

The UText object

<> indicates optional parameters

Constructing UText:

#!lua

local utxt = UText( Text,   Duration, Position, <...>          )
--   table =      ( string, number,   Vector2,  Not Implemented)
--   returns: UText (table)

Functions of the UText object:

Functions of the object require var:function(...) or UText.function(var, ...)

Format()

#!lua
utxt:Format( Format, StartIndex, EndIndex, <FormatFunction>, ................. )
--         ( string, number,     number,   function        , format parameters )

For a list of standard and unofficial formats and their parameters, see the Formats page.

The following text is completely false because of issue #5

If you want to use a format that is not registered, for example one that you want to use inside of your script only (the official Basic Tag chat handler reads from registered formats), then you can specify FormatFunction which is identical to the FormatFunction passed to RegisterFormat (see Static Functions below).

You can also use FormatFunction to initialize any format with a different Format name to have multiple of the same function, but formats are not scripted to handle such things and may conflict with themselves.


GetText()

#!lua
utxt:GetText()
-- returns: string


SetText()

#!lua
utxt:SetText( Text   )
--          ( string )

Note: This function automatically Optimizes when run, no optimization is required.

If you intend to set the text without optimizing just yet, try changing the internal value.


GetDuration()

#!lua
utxt:GetDuration()
-- returns: number


SetDuration()

#!lua
utxt:SetDuration( Duration, <NoReset> )
--              ( number,   boolean   )

SetDuration by default resets the elapsed time on the text so that the UText takes a full amount of the new duration to expire. If NoReset is true, then the time is not reset. If the new duration is less than the current elapsed time (whether from creation or the last duration with reset), the UText will be destroyed on the next render.


Optimize()

#!lua
utxt:Optimize()

Optimize should be run any time there is a direct change to the internal text or formats. The convenience functions Format and SetText automatically optimize. Optimize can be costly if there are frequent and numerous changes, so in certain cases it may be worth modifying internals and optimizing when you know you are ready to render.

Caution: The Render function automatically optimizes, but not unless the internal 'optimized' is false!

Do not rely on the automatic optimization when you make unannounced changes to the internals!


Render()

#!lua
utxt:Render()
-- returns: self (UText)

This should be called in your callback for the Render event, it renders the object. If the internal 'finalcallback' is not set, it returns nil to indicate the object has expired (as a result of duration). If 'finalcallback' is set, it calls that as a function with the object itself as the parameter.



Static Functions of UText:

Static functions do not exist to constructed objects of UText. They must be called as is: UText.functionHere()

RegisterFormat()

#!lua
UText.RegisterFormat( Format, FormatFunction )
--                  ( string, function       )

As of the Alpha release, you must register a format to use it.

See Format Templates or Introduction to Formats in code for more information on how to create a format that you can register.