controller?

Ned Konz ned at bike-nomad.com
Wed Sep 24 14:11:52 UTC 2003


On Wednesday 24 September 2003 02:16 am, ye juan wrote:
> Hello,
>       I am a newer in the group and I have much
> interested in the Squeak environment. So I want to
> know how I can send my questions to members of the
> group.
>      Now I have been learned Squeak with a little
> program. That is I want to control two balls which are
> fall on the floor at the same time when I press a
> button.Now I programmed the motion of the two balls by
> setting their paths and stepTime, but how can I set
> the button to control the balls together.
>     Please write back to me as soon as possible! Thank
> you very much.

Are you using the eToys (scripting) or Smalltalk? This is much easier 
to do with eToys.

If you're using eToys, it would be better to ask on the Squeakland 
mailing list (see http://www.squeakland.org ). In Etoys there is a 
button that will start all scripts ticking, or stop ticking. There is 
still the problem of sending a message to all the objects of a 
certain kind, though you could just name them in a script.

But since you mentioned stepTime, you're probably using Smalltalk.

In Smalltalk, you'd have to have the button send a message to both 
balls. I have found it easiest to do this (in fact I've also done 
this in the eToys environment but I haven't published that work yet):

* When the balls are created, have them listen for an event. I've 
found it useful to register the event on the World:

BallMorph

	intoWorld: aWorld
		super intoWorld: aWorld.
		aWorld when: #startBallsFalling send: #startStepping to: self.
		aWorld when: #stopBallsFalling send: #stopStepping to: self.
		aWorld when: #resetBallsPosition send: #resetPosition to: self.

	outOfWorld: aWorld
		aWorld removeActionsWithReceiver: self.
		super outOfWorld: aWorld.

* When the button is pressed, it then triggers the event:

startBallsButton := (SimpleButtonMorph labeled: 'Start Balls Falling')
	action: #triggerEvent: ;
	arguments: #(startBallsFalling)
	target: ActiveWorld;
	yourself.

etc.
-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE



More information about the Squeak-dev mailing list