alice-teacher Alice 3 Beta version 3.0.3.20

Don Slater dslater at andrew.cmu.edu
Tue Dec 13 13:27:30 EST 2011


Sorry, I forgot the attachment ;-)

Don Slater
---



Lance,
You are wrestling with one of the interesting conundrums of working with Alice. In the scene editor, we are adding and positioning instances of classes (objects), for a program that we have technically not written any code for in our program. So, there is a sense in which these objects are constructed before the program we are writing is executed.

When the Run button in Alice 3 is clicked, the MyScene class is constructed, and in the first step of that construction, the declaration and construction of all the appropriate objects we have added to the scene takes place. After the objects are constructed, the "performGeneratedSetup" method of the MyScene class is called, which positions and sets the properties in the scene, based on the work we did in the scene editor. But notice this positioning takes place after the constructor for the objects have been called. So any code that is in the constructor, may be overwritten in the process of "perform(ing)GeneratedSetup", depending on the state of the objects in the scene editor.

There are two ways to set the color of the moon surface in the scene, and not use the constructor. The scene editor itself allows you to change the color of the surface of the moon. See the attached screen shot "purpleMoon". Then performGeneratedSetup will capture that information. There is also another procedure in the MyScene class called "performMySetup". Any code in this procedure is executed after the code in "performGeneratedSetup", but before the scene window opens and the code in the run procedure is executed.

So if you had set the color of the moon surface to purple in the performMySetup procedure, instead of the constructor, when your scene began to execute the moon surface would have been purple, without the delay.

Admittedly, this makes it difficult to teach about constructors in the Alice 3 environment. As we continue to work and refine Alice 3, this is on our radar as something to revisit. But in my courses now, I do not teach constructors until after we have started looking at Alice code in Java / NetBeans, when I can manipulate the contents of performGeneratedSetup.

Please let me know if you have any other questions.

All the best,
Don Slater

On Dec 11, 2011, at 1:59 PM, Lance Allen wrote:

> I recently downloaded Alice 3Beta. I created a new project using the MoonProject.a3p template. This simply shows a moons surface with a black sky. When the program runs I want the moon's surface to change to a purple color. I would have thought the obvious place for this code would be in MyScene -->MyMoonSurface-->Edit constructor, since you use a class constructor to instantiate the object. However when I run the project the color of the moon's surface does not change.Instead if I place the code in the run procedure and play the program there is a slight delay and then you see the surface change to purple.
> 
> Can anyone help me understand why placing the code in the class constructor does not work? Thank you in advance.
> Lance Allen
> 
> 
> 
> -- 
> _______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20111213/d80b17d1/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: purpleMoon.png
Type: image/png
Size: 261895 bytes
Desc: not available
Url : https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20111213/d80b17d1/attachment-0001.png 


More information about the alice-teachers mailing list