This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-10-28 19:32:03

aadaam
Scratcher
Registered: 2007-10-27
Posts: 3

Sprite-to-Sprite messages instead of broadcasts?

Hi all,

As a software developer/engineer taking most of my time with modeling in UML and other such things, I'd like to suggest this for consideration:

Object-to-object messages

From a programmers point of view, broadcasting is a bit outmoded. Technically speaking - I will explain a line later this - it means global functions, which is strange in an object-oriented world like Scratch, given that messages are sent by objects, but heard globally.

As an example, let's have a cat, which is hit by the stone, and then the cat should loose one life (or die). In Scratch, it looks like:
[blocks]
stone:
<if><touching[ cat
<broadcast[ cat must die
<end>

cat:
<when I receive[ cat must die
(dies)
[/blocks]

Theres' nothing wrong with the second statement (when I receive), but the first sentence is problematic: you don't BROADCAST that the cat should die, you exactly SAY to the cat that she should die!

This was a common element on object-oriented approaches,and most of the time, it's right.

There's nothing wrong with global functions though, sometimes, it's just that it's teached for children, and it's an out-of-model thing, although most of the time necessary to use broadcast. Even if some problems could be solved easier this way, and even if the computer languages at their very heart work this way, it feels phylosophycally incorrect, at least for me.

Offline

 

#2 2007-10-29 19:14:21

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Sprite-to-Sprite messages instead of broadcasts?

This topic has been discussed before (I forget which thread).

I suggested that the "broadcast" block be replaced by a "send" block with two parameters---the message and the destination, with destination being a pulldown list  containing

all
self
stage
sprite1
sprite2
...


Note that sending to self is a good way to retain portability of code---the script can be copied to another sprite and not require editing.

Offline

 

#3 2007-11-06 20:54:59

vgman20
Scratcher
Registered: 2007-11-03
Posts: 44

Re: Sprite-to-Sprite messages instead of broadcasts?

Ummmmmm.... what's the difference between brodcast and that


Ever stop to think...
and then forget to start again?

Offline

 

#4 2007-11-07 01:53:22

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Sprite-to-Sprite messages instead of broadcasts?

Broadcast sends the message to all sprites.  It would be nice sometimes to be able to tell just one sprite to do something, like sending a "fire" command to "bullet3" without having bullet1 and bullet 2 getting the message.

Offline

 

#5 2007-11-07 20:36:52

vgman20
Scratcher
Registered: 2007-11-03
Posts: 44

Re: Sprite-to-Sprite messages instead of broadcasts?

Well if you just don't have a "When I recieve" block for the other sprites it doesn't matter!


Ever stop to think...
and then forget to start again?

Offline

 

#6 2007-11-08 15:41:13

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Sprite-to-Sprite messages instead of broadcasts?

But if I have 20 sprites with the same set of actions, it would be much nicer to have them all have the same scripts, and to be able to say "sprite 13, chase the mouse", "sprite 12, spin in circles", and so forth, rather than having to (number of sprites)*(number of commands) different messages.

Offline

 

#7 2007-11-20 09:54:56

brian11
Scratcher
Registered: 2007-11-20
Posts: 3

Re: Sprite-to-Sprite messages instead of broadcasts?

I am new to sprite and think it is really cool as you can visually program. However, it would be even cooler if it followed the object-oriented model a bit more and allowed you to model sending messages between instances instead of broadcasting.

Also I think it would be great to have some introspection so I can query the state of my sprite - for example are you wearing costume#1.

Also it would be great to programmatically access the cloning of a sprite so I could have a factory to create sprites dynamically during program execution.

Also it would be really great if I could nest sprites so I can have a sprite within a sprite.

Offline

 

#8 2007-11-20 11:59:11

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Sprite-to-Sprite messages instead of broadcasts?

Version 1.2 does allow you to query the state variables (like costume #, x, y, ...) of any of the sprites.  It should be out in early December.

Currently there is no cloning of sprites, though I agree that it would open up a lot of programming possibilities. 

Sending messages to specific sprites (self, all, or a named set of sprites) would be handy also.

Nesting sprites adds a whole lot of additional complexity that I'm not sure is worthwhile in a first programming language for young kids.  You can get that in "Alice" (http://alice.org), but I'm not sure that the price in complexity is worth it.

Offline

 

#9 2007-11-20 12:21:24

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Sprite-to-Sprite messages instead of broadcasts?

Hi brian11,
I agree with most of the things on your wish list. Some things, like the costume# will - I think - be available in the next version that's coming up, others probably not for a long time.

I especially agree that sprite-to-sprite messages, and nested sprites would be a real boost (I'd love that), and runtime instance creation or at least cloning would be nice to have. While we're still short of such powerful concepts in Scratch I am nonetheless constantly and repeatedly amazed at the inventiveness that members come up with when creating projects I did not believe were possible in Scratch.

Sometimes I am myself astonished that ideas that I got used to in more complex programming environments (like recursion, classes and instances, functions etc) can be quite elegantly 'emulated' in Scratch. In fact, at times it seems to me there is almost some kind of 'contest' about getting to the limits of Scratch. Some members, like Canthiar, chalkmarrow and Kevin (and many more) never fail to impress me with their ability to create resourceful projects that would be cool in *any* other language also.

So, I believe Scratch is a wonderful starting into programming, and a great place to come back to once you've visited the 'mature' programming languages to be re-inspired with what programming is really all about: Creating projects to be shared among friends!


Jens Mönig

Offline

 

#10 2007-12-06 16:18:23

lodylody
Scratcher
Registered: 2007-11-14
Posts: 14

Re: Sprite-to-Sprite messages instead of broadcasts?

aadaam wrote:

Theres' nothing wrong with the second statement (when I receive), but the first sentence is problematic: you don't BROADCAST that the cat should die, you exactly SAY to the cat that she should die!

It is another word. It is just the same. I am going to show what it means, in part of my upcoming project.

When a computer is clicked. It broadcasts SATELLITE ON,
Satellite catches. When it recieves the broadcast...      it broadcast ALIENS.


The reason I said that is...                  a satellite BROADCASTS messages to do stuff out in space.

Offline

 

Board footer