alice-teacher World variables and local parameters
André Gustavo Schaeffer
andre_schaeffer at yahoo.com.br
Fri Mar 15 15:39:11 EDT 2013
Bob.
Thank you for your answer.
About the first one (global variable) I will be trying make like you written
next time that I will need.
About the second question, your example was perfect.
I dont know why I had thought that "parameter" was related to a world setup
parameter, instead of thinking the trivial meaning of a simple parameter
passed as value exactly like passing a parameter to a function or procedure,
of any other programming language, but in that case to an object method.
Finally, as a complement of your last observation, I uploaded an a2w file in
.RAR format, but our list server changes it as an .OBJ file, protecting
against firewall mistakes of e-mail servers when downloading :) lol
Just for remember everyone to change de file extension to the correct one
before trying open the file.
i.e.:
Name: Distance2Points.rar <<< RAR compressed file
In URL below, you download an OBJ file. Need change its extension to the
above (rar) and uncompress it to get the a2w file.
Url :
http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20130314/97254c4c/attachment.obj
Think this information can be useful for somebody.
Prof. Andre Gustavo Schaeffer
andre_schaeffer at yahoo.com.br
https://sites.google.com/site/andregustavoschaeffer
Erechim(RS) Brasil
Message: 1
Date: Fri, 15 Mar 2013 14:19:09 +0000
From: Robert Durtschi <robert.durtschi at gcsu.edu>
Subject: Re: alice-teacher s Digest, Vol 32, Issue 8 - World variables
and local parameters
To: "alice-teachers at lists.andrew.cmu.edu"
<alice-teachers at lists.andrew.cmu.edu>
Message-ID:
<7AD5338E8AF6AE4FA8AF2BF7DA00853744E71FFB at BY2PRD0410MB390.namprd04.prod.outlook.com>
Content-Type: text/plain; charset="us-ascii"
>>Does anybody knows how can I pass a value of some variable to a private
>>method of another object?
For example, I have a variable read inside a method of an object, and then I
want to make some calculation using that value but only when I click over
another object.<<
Probably the easiest way is to create a World variable then all objects in
that world should be able to "See" the variable.
the method that reads can update the World variable by dragging the
world.variable into the method i.e.
world.global_variable set value to bunny.local_variable
and then have the calculate method use the global variable from the
"expressions" list:
bunny2.local_variable set value to world.global_variable + 2
>>Another question... what is the objective of using a parameter instead of
>>using a variable?
I thought a parameter in Alice was like a global variable, but it don't
seems to be.<<
Quite the opposite. A parameter is used to modify the behavior of a method
and is only visible to the method and the object that calls (invokes) the
method.
For instance, I use the "Hello World" project from chapter 1 of "An
Introduction to Programming using Alice 2.2" by Herbert, which has a bunny
move forward, turn to face the camera and say "Hello World". We then extend
it by "teaching" the bunny the "hop" method. Then we extend hop by adding
height and length parameters to "tell bunny how high and how far to hop":
bunny.hop ( [123] height, [123] length)
Do together
bunny move up height meters
bunny move forward ( ( length / 2 ) )
Do together
bunny move down height meters
bunny move forward ( ( length / 2 ) )
So the bunny moves up the height specified and forward half the length then
moves down that height and forward the other half of the length.
This assumes Alice 2.3, if you are using Alice 3.2 then the principle is the
same (as it is for Ada, BASIC, C, C++, FORTRAN, etc.) but the actual code
will be slightly different.
If you would like to email me a more detailed explanation of what you are
trying to do and attach your .a2w file I will look at it and try to update
it so it does what you specify. I can be reached at
robert.durtschi at gcsu.edu
(warning, at least on a PC a downloaded .a2w files tries to turn into a .zip
file (which underneath it is) and you will need to do a "save as" chose "all
file types" and change the extension back to a2w, before Alice can open it.)
Bob Durtschi
More information about the alice-teachers
mailing list