Home > Articles

Writing Lingo Scripts

  • Print
  • + Share This
This chapter is from the book

Creating Scripts

To create a script, select an empty location in the Cast panel and press (Command-0) [Ctrl+0]. The Script panel appears. The Script panel also appears when you try to edit an existing cast member, double-click on the frame sprite channel, or use any of the various shortcuts found throughout Director to get access to a frame's, sprite's, or cast member's script.

Using the Script Panel

The Script panel has a few buttons at the top including the typical Director cast member buttons that take you forward and backward in the Cast, enable you to add a new cast member, and enable you to switch cast libraries. Figure 3.1 shows the Script panel.

Figure 3.1Figure 3.1 The Script panel enables you to edit movie scripts, behaviors, and parent scripts.

The rest of the buttons deal with more advanced Lingo functions, such as handlers and debugging. You will learn about them as you learn about those functions.

NOTE

For more information about debugging your Lingo code, see "Using Lingo Debugging Tools," p. 671.

There are five menu buttons that allow you to quickly access various Lingo commands. The first two are for alphabetized and categorized general Lingo, the second two are for 3D-specific Lingo, and the last is for Lingo added to Director via Xtras. These five menus enable you to hunt for and automatically insert any Lingo keywords into your script. They come in handy when you just can't remember the name of a command, but you have a good idea of how it starts or under which category it falls. They are also handy in refreshing your memory as to the proper syntax for using Lingo commands.

Script Cast Member Properties

A script cast member's properties can be changed with the Property Inspector. Script cast members have one script-related property: the type of script. The three options, of course, are Movie, Behavior, and Parent. You can also use the Link Script As button to use an external file, rather than an internal member, as the script text.

Linked scripts can be used to allow several movies to share a single script. The code resides in an external text file that you can edit with any text editor. Linked scripts also permit what is called source control—you can check your scripts into a source database, keep track of changes to scripts, perform backups, and so on.

A Typical Frame Script

So what sort of code gets placed in script members? It depends on what the script is used for. For instance, if a behavior script is placed in the Score in the frame's script channel, then it is called a frame script. Here is an example of a very typical frame script:

on exitFrame
 go to the frame
end

This small piece of code is called a handler. A handler starts with on and the name of the handler, in this case exitFrame. A handler ends with the word end.

There are two types of handlers: event handlers and custom handlers. Event handlers use names that match specific events in Director. The exitFrame event occurs when Director is done displaying a frame and is about to move to the next frame.

The other type of handler, a custom handler, is never called by Director, but is instead called by a piece of code that you write. In other programming languages, these are known as procedures or functions.

Everything in between the on and end lines is the code that runs when the handler is called. In this example, go to the frame is the only code. This is a simple command. The go to command tells Director to jump to a new frame in the movie. The the frame portion of the line identifies the current frame by number.

NOTE

Lingo is very forgiving and will also accept go the frame instead of go to the frame.

So, go to the frame is basically commanding Director to jump to the frame that it is already on. The exitFrame event is called just before Director is about to leave the current frame and continue on to the next one. Instead, the script tells it to simply repeat the current frame.

The result of this common script is that the movie will repeat the same frame over and over again. This is the preferred technique for getting the movie to pause on a frame. It is used for presentations, applications, games, and just about every other type of Director movie outside of straight animation.

A Typical Button Script

Buttons can be almost anything in Director. For instance, they could be bitmaps, shapes, Flash members, or even Director's own button member. Regardless of the media used, you'll need a script applied to that sprite to make the button work.

A button script can react to a number of events. The most common one would be the mouseUp event. This occurs when the user has completed a mouse click on that sprite. Here's a simple button script:

on mouseUp
 go to frame 3
end

When the mouseUp event occurs, the on mouseUp handler will be called. The code in it will make the movie jump to frame 3.

You can use a button script like this, along with the previous looping frame code, to build a simple presentation. The movie initially loops on frame 1. When the user clicks on the button, the movie jumps to frame 3. You can see these two scripts in the file called simplescripts.dir on the CD-ROM.

NOTE

For more information about button scripts, see "Creating a Simple Button Behavior," p. 325 (Chapter 12).

Reusing Scripts

In the simplescripts.dir example, when the user clicks on the button, the movie jumps to frame 3. The movie then loops on frame 3, just as it looped on frame 1. Since the behavior of frame 1 and frame 3 is the same, they can use the exact same script. They don't use a copy of the same, script, but instead the exact same script cast member is applied to both frames.

Figure 3.2 shows the score for the simplescripts.dir movie. You can see that the same script has been applied to both frames 1 and 3.

Figure 3.2Figure 3.2 The Score shows a simple two-frame presentation that reuses the frame script.

In a simple presentation, the looping frame script may be used on all of your frames. There is never a need to create a new frame script or make a copy of this script.

Testing Lingo with the Message Panel

Although Lingo scripts are usually stored in cast members, you can also run short, one-line programs in something called the Message panel. Open the Message panel by choosing Windows, Message, or by pressing (Command-M) [Ctrl+M].

The Message panel has two modes in Director MX. The split-pane mode divides the panel into two portions: the top typing portion and the bottom output portion. If you have it set to this mode, change it to the single-pane mode by dragging the divider bar down to the bottom of the panel like in Figure 3.3. Or, you can click on the button in the middle of this divider.

Figure 3.3Figure 3.3 The Message panel enables you to type single lines of Lingo code and see the results.

Type put 42 into the Message panel. When you press (Return) [Enter], the Message panel interprets what you just typed and returns -- 42 on the next line. Figure 3.3 shows how the Message panel now looks.

The double dash, --, appears before lines that Director returns to you in the Message panel. Later, you will learn how to use the double dash to comment your code.

NOTE

For more information about commenting your code, see "Writing Good Code," p. 662.

The put command is used to place text into the Message panel. It has some other uses that you will learn much later.

NOTE

For more information about the put command, see "Using String Variables," p. 295.

You asked Director to put the number 42 into the Message panel. It did just that. But it did more than just echo a number back at you. It actually understood what you meant by 42. To prove it, try this:

put 42+1
-- 43

Now you see that Director can add. It doesn't merely spit back 42+1, but instead understands that these are numbers and that the plus symbol means that they should be added together.

You can do other things with Lingo besides math. Try this in the Message panel:

beep

You should hear your computer's default system beep. If you don't, it is probably because your volume is turned down or your system beep is turned off.

Notice that the Message panel does not return anything in the next line, because you didn't ask it to. The command beep simply plays the system beep. It does not place anything in the Message panel as the put command does.

The Message panel is nice for taking your first Lingo steps, and it continues to be useful as you learn new Lingo commands. Even expert Lingo programmers use the Message panel constantly to program in Lingo.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020