Home
Project Folders
Teacher Resources
Student Resources
How Do I?
Literacy
MWForum
Site Map
Search
Our Team

MWForum Message [Date Index] [Threads] [Authors] [Attachments] [Subscribe]

[Thread Prev] [Thread Next]

To: <MWcybercourse@xxxxxxxxxxxxxxx>
Subject: RE: Variables
From: "Wendy Petti" <wpetti@xxxx>
Date: Fri, 2 Nov 2001 20:52:33 -0500

Mike's example used a local variable, established with "let."
Maybe it would seem more accessible with an example of a global
variable. I'll show the same basic procedure set up three ways:

Aassume you have a slider named stepsize. You want to draw 100
steps of the size indicated on the slider.

STEPS1 uses just the slider itself as the variable:

to steps1
repeat 100 [fd stepsize rt 90 fd stepsize lt 90]
end

STEPS2 uses a global variable (stepsizevalue) which is set to the
same value as the value on the stepsize slider:

to steps2
make "stepsizevalue stepsize
repeat 100 [fd :stepsizevalue rt 90 fd :stepsizevalue lt 90]
end

STEPS3 sets up stepsizevalue as a local variable:

to steps3
let [stepsizevalue stepsize]
repeat 100 [fd :stepsizevalue rt 90 fd :stepsizevalue lt 90]
end

(Notice that when you use the slider's name in the procedure, it
is NOT preceded by a colon, but after you create a local or global
variable, then when you call its value in the procedure, its name
IS preceded by a colon.)

With any of these procedures, you still control the size of the
steps using the stepsize slider.

By the way, I've thought of a time when you would NOT want to use
a local or global variable to hold the slider's value: Sometimes
you want to be able to change the value of a slider while a
process is running. For instance, it is fun to make a shape grow
and shrink simply by moving a slider back and forth... or it is
fun to steer a shape around the page using a slider which controls
its heading while it is moving. If you have set the value of a
variable to the initial value on the slider, then you cannot have
dynamic control over the variable while the procedure is running.

Wendy

> -----Original Message-----
> From: Gary McCallister [mailto:mccallis@xxxx]
> Sent: Friday, November 02, 2001 6:42 PM
> To: MWcybercourse@xxxxxxxxxxxxxxx
> Subject: RE: Variables
>
>
> I didn't realize that what was suggested allowed the
> best of both worlds. I am not an accomplished
> programmer and didn't exactly follow what Mike is doing .



  • Previous by thread: RE: Variables
  • Next by thread: Re: variables

  • To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.


    © copyright 2001 - 2008