View this PageEdit this PageUploads to this PageVersions of this PageHomeRecent ChangesSearchHelp Guide

The Real World vs The Virtual World

Things, Properties, and Behaviors (Real World) vs. Objects, Variables, and Scripts (Squeak)

Take a few moments to describe the world. Or the room you're in. Chances are you talked about things like flowers and trees or chairs and tables. You may have described their physical attributes or properties (like tall and green or short and brown). If you described a thing that does something , that is, has some behavior, then you needed to talk about what it does, and perhaps when or under what circumstances it does it. For example, people eat (when they're hungry).

We describe our world, or little pieces of it, by describing the things that occupy it, all of the properties that the things have, and the behaviors of the things.

My car is yellow, it is 20 feet long, 4.5 feet high, and is 6 years old. It moves (when I press on the gas pedal), but it uses gas when it does. It doesn't move it is facing a brick wall or if the battery is dead or if there is no gas. My car is made up of many other simpler things (like a steering wheel, four tires, nuts, bolts, an engine (which is made up of other simpler things), etc. To completely describe it would be, well, an engineering feat. What matters to me most, as the user, are that it behaves as it is supposed to (it brakes when I step on the brake pedal, for example), that it is my favorite color, has room for my family, etc.

If I want to write a program that modeled my car, I have many choices. I can draw a blue object that looks kind of like my car, have a button that is the "gas pedal", another that is the brake, and have a steering wheel that when turned will make my drawing rotate on the screen. What about gas? I could add more realism and detail by keeping track somewhere of the amount of gas that it has, and making sure that the gas is used up as the car is driven. What other details should I put in? It all depends on how accurately I want to capture the car's look, feel, and behavior. (A sophisticated program like "Gran Turismo 4" for playstation, or other similar products, allow you to swap tires, engines, etc. and modify your vehicles. Each change results in a change in performance, as different tires grip the road differently. When braking, depending on the suspension, the car's weight is pitched forward, which affects steering. And so on. If the goal is a simulation that approximates reality in form and function, then the programming can be enormously complex. )

Writing programs for a virtual world is similar. The world is made up of things called objects. What is an object? It is anything you want it to be. It is something that you draw, or that you pull out of the supplies bin in Squeak, or it is something that is composed of many smaller such parts.

Writing programs in Squeak, or in many object-oriented programming languages, amounts to describing a collection of objects (the "things"). Each object has variables or properties that describe its basic attributes (such as height, width, length, color, speed (say, for cars), or height, hair-color, age, mood (for people). These attributes can be constant (like a car's width), or may vary (like a person's age). Since in principle, any of these can be changed, we call them all variables.

Finally, in addition to specifying what the objects are, we must also say how they behave, which is done by writing scripts in Squeak (called "methods" in Java).

Let's introduce our guide Claire Uploaded Image: Claire.gif which is a sketch I drew. Claire is also an object. Let's open up a viewer for our guide by clicking on the light blue eyeball icon at the left edge of Claire's halo. (Recall that you alt-click or command-click on the object to bring up its halo). You might see something like this:

Uploaded Image: ClaireViewer.gif.

In the next sections, we will explore many of these in detail. The thing to notice now is that, besides the category pane "tests", most of the entries in the other categories either have a yellow exclamation point Uploaded Image: exclamation.gifto the left of them, or have a green arrow in a purple background Uploaded Image: greenpurplearrow.gifnear the right. In general, the following is true:
  • Uploaded Image: exclamation.gifA yellow exclamation point indicates a script, which is a behavior that the object can carry out. This holds whether the command is built-in (like "forward"), or whether it is a more complicated script that you have written.
  • Uploaded Image: greenpurplearrow.gifA green-on-purple arrow indicates that the line corresponds to a variable, or property of the object, that can be changed either by hand, or by a script that is running.

We shall see that writing a program amounts to defining objects, the properties (variables) they have (though many come for free), and what behaviors (scripts) they have.

Link to this Page