Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Thread Tools Display Modes
Variables? Parameters? All verry confusing! help!
Posts: n/a
Question Variables? Parameters? All verry confusing! help! - 03-03-2007, 08:21 PM

hey there, im totally lost with variables and parameters. in the first place, what are they??!?! someone told me they are like little codes u can use for shorcuts..? please tell me the real purpose, and how to make them both! Thanx!!!
Reply With Quote
variables and parameters
Posts: n/a
Default variables and parameters - 03-04-2007, 11:53 PM

Hello Rohma,

You really need to spend a little time reading about this -- in general or particularly for Alice.

Here are a few paragraphs from some stuff I wrote about Alice that might help get you started.

The data that represents an object is organized into a set of properties. Each property describes the object in some way. For example, the color of an object, its location, the direction in which it’s facing, and so on, are all properties of an object. A computer manipulates an object by changing some of its properties or some of the properties of its sub-parts. For instance, an airplane’s autopilot might change the angle of a wing flap (a sub-part), which in turn affects the entire airplane.

The programs that manipulate the properties of an object are called the object’s methods. We can think of an object as a collection of properties and the methods that are used to manipulate those properties. The values stored in the properties of the object at any one time are called the state of the object. This modern approach to computer programming is known as object-oriented programming, or OOP for short.

A variable is a name for a memory location that temporarily stores a value while a method is running. Variables are a lot like the properties of objects. They have data types, just like properties, and they are stored in the memory of the computer, just like properties. However, properties are associated with an object, and their values are maintained as long as the object exists, whereas variables are associated with a particular method, and their values usually exist only inside the method. Once the method stops running, their values are gone, unless, of course, you had saved them somewhere else while the method was running.

A parameter is a variable whose value is passed from one method to another— just like a baton is passed from one runner to another in a relay race. Thus, a variable is a value that can change inside a method, and a parameter is a variable whose value is passed from one method to another. You had to tell the cheshireCat.move method that you used inside your cheshireCat.jump method in the last exercise the direction and amount you wanted the cheshireCat to move. These values are parameters for the primitive cheshireCat.move method. Your cheshireCat.jump method passed the values up (or down) and 1 meter to the move method when the move method was called to perform its task.

The last paragraph makes reference to a project with an instruction something like this:

cheshireCat move [forward] [1 meter]

Forward and one meter are parameters.

I hope this helps. Look for a good book on Alice on the Internet. Last time I checked there were about 8 of them in print. Also, ask a programming teacher or a friend who programs if you can borrow an introductory programming text. They'll probably give an old one that you can keep. It should tell you what you need to know about variables, etc. A book that covers object-oriented programming is probably best.
Reply With Quote
Posts: n/a
Default 03-30-2007, 09:52 PM

Hello Rohma,

This may be your lucky day. I have just finished publishing the ninth lesson in my new tutorial series on Alice Programming for aspiring programmers who have no background or experience in programming. The ninth lesson covers Data Types and Variables.

The following list shows the titles of the other lessons in the series that I have published so far. I will be publishing additional lessons on a schedule of one or two lessons per week.

100 Getting Started
105 Setting the Stage
110 Objects in 3D Space
115 Setting the Stage Manually, Part 1
120 Setting the Stage Manually, Part 2
125 Your First Alice Program
130 The Program Development Cycle
135 Functions that Return Values
140 Data Types and Variables
900 Appendix A Primitive Methods

These lessons are freely available for online study, and executable versions of the sample programs in the lessons can be downloaded and executed in your Alice environment.

You will find a link to the Table of Contents for the series (titled Learn to Program using Alice) near the end of the page at the following URL:

The material in the lesson on variables depends heavily on an understanding of the material in the earlier lessons, so you may need to start at the beginning and work your way through to the lesson on variables.

Dick Baldwin
Reply With Quote
Watch out with variable names.
Posts: n/a
Exclamation Watch out with variable names. - 03-31-2007, 12:12 PM

One minor comment to add to the earlier (excellent) postings. A variable defined in an object's property list is a completely different variable than one with the same name defined locally in one of the object's methods, even when both have the same simple name.

This difference is often not obvious in a simple Alice listings unless you go to a pulldown menu (see attached, and try running the world with both variables). This is a good thing to check if your program isn't running like it should.
Attached Images
File Type: jpg Variable Names.JPG (26.8 KB, 278 views)
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Copyright ©2021, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.