LOOPE - Lingo Object Oriented Programming Environment by Irv Kalb
Table of Contents
Section 1 - Parent Scripts and Objects
What is an Object
Lets start with a definition. An object is, "data, plus code that acts on that data, over time". Thats it. Thats all there is. Sounds simple doesnt it? This seemingly simple concept can be the key to designing and writing code in a whole new way. As this "book" progresses, I will attempt to demonstrate how looking at problems from an object oriented programming (OOP) point of view will lead to a different style of programming than using a structured programming approach.
One problem in computer science is that people who come from different backgrounds sometimes use different words to refer to the same things. For example, many people call something which appears on the screen an object. However, in the Director world, a graphic that lives in a channel and is intended to be seen on the screen is called a sprite. In computer science, it is important that people agree on terms for things so that they can be precise when exchanging information. This ensures that the real intended meaning is conveyed. Because terms are still evolving, I will attempt to foist my own nomenclature on you, the reader. However, I will attempt to use as many "industry standard" terms as possible.
If we look again at the definition of an object, we see that it is made up of data and code. The data and code of an object have special names. In any programming language, data is always stored in one or more variables. In Lingo, each piece of data in an object is called a property variable or more simply, a property. In some other languages, the data are referred to as instance variables. In Lingo, any piece of code that starts with an "on" statement and ends with an "end" statement is called a handler. In other languages, these fundamental chunks of code may be referred to as subroutines or simply routines. However, there is a special term among OOP programmers to differentiate handlers within objects from handlers outside of objects. A handler within an object is commonly referred to as a method. So rolling in this new terminology, objects in Lingo are made up of properties and methods.
In Director, script cast members come in three different flavors; Movie Scripts, Behavior Scripts (also known as Sprite Scripts), and Parent Scripts. Objects are defined in a Parent Script. (Behaviors are actually definitions of objects also, but lets not get ahead of ourselves.) Lets take a look at a Parent Script just to see what properties and methods look like.
on new me
pCount = 0
on mIncr me
pCount = pCount + 1
on mDecr me
pCount = pCount - 1
on mGetCount me
This is a simple parent script. At the top of the script is the definition of any properties. This script has only one property, pCount. Following that, are the methods of the script. This parent script has four methods: new, mIncr, mDecr, and mGetCount. We will get heavily into how scripts like this work in a later chapter. Notice that the data and code are combined into a single script. The next chapter on naming conventions will discuss the scope of variables. But for now, it is enough to recognize that a property variable, such as pCount in this script, is available to be used by any or all of the methods of an object. Any method can access the variable pCount, and the current value of pCount will be remembered between calls.
Table of Contents