Using Director > Writing Scripts with Lingo > Writing Lingo statements |  |

Writing Lingo statements

When you are writing statements in a Lingo script, you can choose between two types of syntax: verbose syntax and dot syntax.

Verbose syntax

Verbose syntax is similar to English. Because of this, verbose syntax is an excellent way to learn to program for the first time: as a new programmer, you can read verbose Lingo and get a fairly good idea of what it is doing. Most users will start out writing Lingo exclusively with verbose syntax because it is so easy to understand.

Here are three examples of verbose Lingo that is very English-like and has a literal meaning:

    set the stageColor to 255
    put the text of member "Instructions" after member "Introduction"
    if x=5 then
    	go to frame 22
    end if

Almost all of Lingo's functionality is available through verbose syntax, but there are a few exceptions. Most of these exceptions are found in Lingo used for manipulating text.

The disadvantage of verbose Lingo is that it can quickly become very long when you write complex scripts. Longer scripts are harder to read and debug. Once your scripts reach a certain level of complexity, you may find it easier to use dot syntax.

Dot syntax contains several examples that compare verbose and dot syntax.

Dot syntax

Dot syntax is a concise form of Lingo that makes longer scripts easier to read and comprehend for users who have at least a novice understanding of the language. By understanding and using dot syntax, you can make your scripts shorter and easier to read and debug.

If you are just beginning to learn Lingo, you will probably want to start with verbose syntax and then begin using dot syntax as your understanding of Lingo improves. You can use verbose syntax and dot syntax in combination. You may want to do this as you begin the process of learning dot syntax.

Because most users will want to use dot syntax after they achieve a basic understanding of Lingo, most of the Lingo examples in this book are written with dot syntax. However, this chapter will provide extensive examples of both syntaxes.

Almost any Lingo statement can be written with either verbose syntax or dot syntax. The following example demonstrates how the two types of syntax relate to each other.

This statement sets the forecolor of sprite 12 to 155 using verbose syntax:

    set the forecolor of sprite 12 to 155

The following statement does the same thing by using dot syntax. It also omits the `set` command, which is optional:

    sprite(12).forecolor = 155

You can use dot syntax to express the properties or functions related to an object or to specify a chunk of text within a text object. A dot syntax expression begins with the name of the object, followed by a period (dot), and then the property, function, or text chunk that you want to specify.

For example, the `loc of sprite` property indicates a sprite's horizontal and vertical position on the Stage. The expression `sprite(15).loc` refers to the `loc of sprite` property of sprite 15.

As another example, the `number` cast member property specifies a cast member's number. The expression `member("Hot Button").number` refers to the cast member number of the Hot Button cast member.

Expressing a function related to an object follows the same pattern. For example, the `pointInHyperLink` text sprite function reports whether a specific point is within a hyperlink in a text sprite. In addition to the syntax demonstrated in the Lingo Dictionary, you can use the dot syntax `textSpriteObject``.pointInHyperlink()` to express this function.

The following `put` statement will evaluate the specified expression and return `TRUE` or `FALSE` depending on whether the pointer is located over a hyperlink in the text sprite in channel 3:

    put sprite(3).pointInHyperlink(mouseLoc)

This is how the same statement is written with verbose syntax:

    put pointInHyperlink(sprite 3, the mouseLoc)

To identify chunks of text, include terms after the dot to refer to more specific items within text. For example, the expression `member("News Items").paragraph(1)` refers to the first paragraph of the text cast member News Items. The expression `member("News Items").paragraph(1).line(1)` refers to the first line in the first paragraph. These text chunk expressions are available only with dot syntax.