Goal

In this exercise you will learn how to use Lingo to work with strings and Text Cast Members.

Background:

Director provides many tools and utilities for creating and editing text assets. There are essentially two types of "container" objects for text, fields and text cast members. There are advantages and disadvantages for each type, but this exercise will focus on Text Cast Members because of their great flexibility and Lingo support. Creating a Text Cast Member is easy, and putting text into one is as simple as typing text in a word processor. However, Text Cast Members are fully supported with Lingo and include numerous properties that make them extremely versatile for use in movies. In this exercise we will explore some of the basic features of Text Cast Members, as well as methods for manipulating the text within them.

Strings:

Text Cast Members are containers for strings. A string is a collection of alphanumeric characters. Strings are useful for providing messages and collecting information in your movies. Here are two examples of strings:

abcdefg is a string.

a1b2c3 is a string.

Notice that strings may contain just letters, or a combination of letters and numbers. Lingo understands a string based on how many continuous characters long it is. Whenever Lingo encounters a space, it considers that the end of that chunk of the string. For example, Hello there has two chunks because there is a space between the words 'Hello' and 'there'. The space is itself an invisible character to Lingo. The space character is considered a delimiter. In computer programming, a delimiter is a character that identifies the beginning or the end of a character string, or a contiguous sequence of characters. You can tell Lingo to use a different character symbol for a delimiter, but the default is the space character. Hellothere is considered one word to Lingo because it contains no spaces.

Another type of string is a literal string, which is a string enclosed by double quotes.

"Hello" is a literal string. "Hello there" is a literal string with two chunks.

Lingo uses double quotes to determine whether a string is to be considered a keyword or statement, or whether it should treat it literally. Usually, literal strings are used to identify the names of Cast Members, for example. The first Lingo statement below does not contain a literal string, but the second Lingo statement does.

_movie.go(10)

_movie.go("10")

On the first line, Lingo will move the playhead to go to frame number 10 in the score. On the second line, Lingo will move the playhead to a frame labeled "10." The quotes make a big difference, in this case. This is an important distinction to make because the computer doesn’t know your intentions in either of the above Lingo statements; it only knows what each line states.

String Concatenation:

It is often desirable to connect two or more strings together, so they appear as a single phrase. The joining together of two or more stings is known as concatenation. Each computer language has different methods and rules for concatenating strings, but in Lingo the ampersand '&' is used. Whenever Lingo encounters an ampersand it joins together the strings into one. For example, if you type the following in the Message Window, followed by a return:

trace("Hello" & "there")

The computer will display:

-- "Hellothere"

Note: The examples in this lesson use the 'trace()' function to output text to the Message Window. The 'put()' function works equally well, though it is officially deprecated, so the preferred syntax is 'trace()'.


The computer joins the two strings "Hello" and "there", but it concatenates them as a single word, with no spaces. What we need to do is pad one of the strings with a space. Padding means you will include an additional space as part of the string, usually at the beginning or end of a string. The padded statement would look like this:

trace("Hello " & "there")

Notice the additional space typed between the "o" of "Hello" and the double quote. The result is that "Hello there" is displayed in the Message Window as two separate words, which reads much better.

You can concatenate as many strings in this way as you like. For example:

trace("Hello " & "there, " & "folks.")

The result is:

-- "Hello there, folks."

Another way to pad a string is to to place two ampersands ' &&' together. This is equivalent to a padded space, so the above statement could be rewritten as:

trace("Hello" && "there," && "folks.")

The end result is the same, and it’s more a matter of style and your personal preference.

You can also combine literal and non-literal strings in the same statement:

trace("Are there" && 50 && "people in this phone booth?")

The result is:

-- "Are there 50 people in this phone booth?"

Notice that there are essentially three string chunks in the above example. 'Are there', '50' and 'people in this phone booth?' The double-ampersands concatenate the chunks, even though the number 50 has no double-quotes around it, and is considered a non-literal string. The above string could also be written as:

trace("Are there 50" && "people in this phone booth?")

or simply:

trace("Are there 50 people in this phone booth?")

As you can see, you have a number of options to consider when crafting and displaying strings. In some cases you will need to concatenate several strings and you will not be able to write it in the simple form shown above. You will also find that sometimes it is necessary to use a variable to store part of what is displayed in in a string. You have the option to substitute a variable for any part of a string, and the value stored in the string will be displayed. The handler below demonstrates this.

showPythonInfo script 
The keyword 'QUOTE' prints a literal quote inside a text string and the keyword 'RETURN' prints a literal carriage return inside a text string. You can choose to use these keywords if you need to have the computer print quotes or a carriage return in the string. You will see the keyword 'QUOTE' used in the handler above to print quotes around the name "Monty Python's Flying Circus."

If the above handler was placed in a Movie Script, and called from the Message Window it would display:

trace(showPythonInfo())

-- The comedy television program, "Monty Python's Flying Circus," first aired in 1969.

Though the 'fullString' variable is somewhat complex and hard to read, it is versatile and contains a number of string variables that can be easily altered to deliver a variety of messages.

The 'showPythonInfo' handler above is a function that returns a string when it is called. The double parenthesis '()' at the end of the handler name when the handler is called indicate this. The 'showPythonInfo()' function could be placed anywhere in a movie, but handlers such as this are best placed inside a Movie Script because you might want to access it from potentially anywhere within your movie, not just from a single sprite instance.

Now that you have a better idea of how to manipulate strings in Lingo you can apply these principles to a Text Cast Member. Simply type the text you want in the Text Cast Member and use Lingo to alter the text when the movie is running. For example, if the above text was a part of a Director movie it might appear in a Text Cast Member as:

02-text-window

The Text Cast Member Window is like a simple word processor and has many features. It's worth spending some time familiarizing yourself with these features. Among the most useful features are choice of Typeface, Alignment, Line Spacing, Kerning, and Typeface Point Size. There are also numerous properties for the Text Cast Member itself, which can be seen in the Property Inspector Window. The image below shows the properties for the above Text Cast Member:

Let's highlight some of the most frequently used properties:

Framing - This controls how the area of the Text Cast Member appears on the Stage. The 'Adjust to Fit' will adjust the framing of the field to fit the contents. The 'Fixed' setting will hold the dimensions of the field you drag out, no matter the contents. The 'Scrolling' option turns the field into a scrolling type, which is most useful when you have a lot of text to display.

If you want the user to be able to type in the field while the movies is running you will want to check the 'Editable' option.

Peruse the Property Inspector palette to explore the other properties of Text Cast Members.

03-text-properties


Below are examples of Text Cast Member Lingo statements you should try, to help you learn more about properties of Text Members and how to access and change the text contained within them. You may download this example movie, or create a movie having a Text Cast Member. If you create your own movie it will need a Text Cast Member with a name of "Monty Python Info." Otherwise, you will need to change the name of the referred Text Cast Member in the examples below.

Using the Message Window we can easily explore other text properties that may be accessed using Lingo.

Try the following statement to extract just the first word of the Text Member named "Monty Python Info":

trace(member("Monty Python Info").text.word[1])

-- "The"

The following will extract just the first character of the first word:

trace(member("Monty Python Info").text.word[1].char[1])

-- "T"

The following will extract the first three words of the Text Member:

trace(member("Monty Python Info").text.word[1..3])

-- "The comedy television"

To erase a Text Cast Member you can assign its text a value of EMPTY, using the '=' operator, or you may use two quotes without anything in between. Both methods are shown below.

-- clear the contents of a Text Cast Member - Method 1
member("Monty Python Info").text = EMPTY

-- clear the contents of a Text Cast Member - Method 2
member("Monty Python Info").text = ""

There are many other possibilities for working with Text Cast Members using other Lingo commands. These examples are intended to give you a basic idea of what's possible.
 

Exercise:

Create a Director Movie that contains at least one Text Cast Member. Experiment by changing the contents of the text using Lingo. Here are some properties and methods to try:

  • Combine strings with printed QUOTE and RETURN symbols inside the Text Member to produce various combinations of words and numbers.
  • Change the 'Text Framing' to a 'Scrolling' style to see how scrolling text fields work.
  • Turn on the editable property of the Text Member to allow the user to type into the field while the movie is running. You can store what the user types into a variable and use the value for features in your movie, or to add a personalized touch to the movie, such as printing the user's name in text phrases used in the movie.

<     Table of Contents     >