Game Development Community

A Note on the t2dTextObject Class

by Eric Robinson · in Torque Game Builder · 02/20/2007 (10:47 pm) · 3 replies

This post exists for anyone wondering how to actually change text on official t2dTextObject objects.

SetText
// %object is a t2dTextObject.
%object.text = %someStringToShow;
GetText
// %object is a t2dTextObject.
%textString = %object.text;

As it turns out, most of the t2dTextObject's data is directly accessible in this way from script. From the TGB Reference file.
text			//The text that is displayed by the object.
font			//The name of the font to render the text with.
wordWrap		//Whether or not text should automatically wrap to the next line.
hideOverflow		//Whether or not text outside the object bounds should be hidden.
textAlign		//The alignment of the text within the object bounds.
lineHeight		//The height, in world units, of each line.
aspectRatio		//The ratio of a characters width to its height.
lineSpacing		//The amount of extra space to include between each line.
characterSpacing	//The amount of extra space to include between each character.
autoSize		//Whether or not the object should be scaled when the text is changed.
fontSizes		//Space separated list of font sizes the text object should use.

I was confused about how to use this stuff and figured that perhaps other people may be confused as well. Hope this helps someone.

#1
02/21/2007 (7:41 am)
This is a subtle but general trend with future TGB releases, as well as stock Torque, and actually comes from C#.

C# has the concept of "implicit accessor methods" that are called whenever you appear to be directly accessing a variable or field, and we've found it quite useful as well as much cleaner in use, so it's becoming a future standard for Torque objects.
#2
02/21/2007 (8:20 am)
Good to know.
#3
02/21/2007 (4:40 pm)
Wow, that stuff looks really cool! For anyone who's never used C# and is interested in what Stephen was saying, take a look at this.

@Stephen: Is this a planned feature of upcoming TorqueScript revisions? Or is there an upcoming switch to a Mono/C# for scripting purposes...?