How to make a button in Etoys 4.1 update 2390 change color of a morph

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make a button in Etoys 4.1 update 2390 change color of a morph

mstram
I'm trying to setup a simple etoys project with a playfield, button
and rectange.

When the button is pushed the rectangle should change color from it's
default of black to red.

1)I've dragged out a playfield, button and rectangle from the
supplies,  placing the rectangle, and button inside the rectangle.

2) I opened a viewer on the button, and dragged the empty script to an
empty place on the workarea (not in the playfield), then added a test
tile, and a "button down?" condition to the test.

When viewing the script textually it shows :
------------------------
script1
        ActiveHand anyButtonPressed
-----------------------------------------------------

3) I then switched the button script back to "revert to tile version"

4) I opened a viewer on the rectangle, and dragged the 'Rectangle1's
color' tile to the workarea, and tried to drop it into the  Test /
"yes" slot in the button's script editor, but it doesn't accept it.

Do I need to use a variable (player type) in the button script to
reference the rectangle's color attribute ?

If so, how ?

-----------------
I could do this same thing "manually" just using a custom class
subclassed from morph,  adding code to the handle down etc, but am
trying to figure out how to using the supposedly "eaier" Etoys :/

Mike
_______________________________________________
squeakland mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: How to make a button in Etoys 4.1 update 2390 change color of a morph

Scott Wallace
Hi, Mike.  

On Mar 14, 2012, at 1:23 PM, Mike Stramba wrote:

> I'm trying to setup a simple etoys project with a playfield, button
> and rectange.
>
> When the button is pushed the rectangle should change color from it's
> default of black to red.
>
> 1)I've dragged out a playfield, button and rectangle from the
> supplies,  placing the rectangle, and button inside the rectangle.
>
> 2) I opened a viewer on the button, and dragged the empty script to an
> empty place on the workarea (not in the playfield), then added a test
> tile, and a "button down?" condition to the test.

Instead of using Test/Yes/No tiles testing for "button down?", you should make the script itself trigger on "mouseDown".  (Click on "normal" in the scriptor's header to get list of choices that includes mouseDown.)  Then it will trigger only when the mouse goes down on the button.

[confusingly, the "button down?" tile reports whether any mouse is down anywhere on the screen, so it's definitely not what you want here.)


> ...4) I opened a viewer on the rectangle, and dragged the 'Rectangle1's
> color' tile to the workarea, and tried to drop it into the  Test /
> "yes" slot in the button's script editor, but it doesn't accept it.

You can't drop it into an empty Yes or No area because no "watcher" or "getter" (such as Rectangle's color) can by itself comprise a line of script.  They require entire executable lines of script, such as Rectangle's x <- 50, or Rectangle turn by 30.


> Do I need to use a variable (player type) in the button script to
> reference the rectangle's color attribute ?

No, I think you'd just want to use a *setter* for the Rectangle's color (drag from the left-arrow in the viewer line for Rectangle's color in its Viewer).


So, in summary:  make a scriptor for the button, as you did, and set it up to fire on mouseDown.  Make the body of that script consist of a "setter" for the rectangle's color, which you can obtain from the rectangle's viewer.

Hope I'm understanding your questions correctly :)

  -- Scott
_______________________________________________
squeakland mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/squeakland