Discuss Scratch
- Discussion Forums
- » Suggestions
- » Sending messages to one object instead of broadcast
- tomkarp
-
New Scratcher
2 posts
Sending messages to one object instead of broadcast
Hi,
Scratch can be useful to introduce objectoriented programming.
But you only have the opportunity to send messages to all objects as broadcast message.
I think it would be much more OO-like to have the possibility to send messages to just
one object. So it would be exactly consistent to other languages where you would write:
myObject.doSomething()
I would be happy to see that feature in Scratch.
So the block
should have an entry where I can choose the object, that should get the message.
The existing block, that sends messages as broadcast could remain of course.
Perhaps other people would like this option, too?
Regards, Thomas Karp
Scratch can be useful to introduce objectoriented programming.
But you only have the opportunity to send messages to all objects as broadcast message.
I think it would be much more OO-like to have the possibility to send messages to just
one object. So it would be exactly consistent to other languages where you would write:
myObject.doSomething()
I would be happy to see that feature in Scratch.
So the block
broadcast [ v]
should have an entry where I can choose the object, that should get the message.
The existing block, that sends messages as broadcast could remain of course.
Perhaps other people would like this option, too?
Regards, Thomas Karp
- Blaze349
-
Scratcher
1000+ posts
Sending messages to one object instead of broadcast
Hi,
Scratch can be useful to introduce objectoriented programming.
But you only have the opportunity to send messages to all objects as broadcast message.
I think it would be much more OO-like to have the possibility to send messages to just
one object. So it would be exactly consistent to other languages where you would write:
myObject.doSomething()
I would be happy to see that feature in Scratch.
So the blockbroadcast [ v]
should have an entry where I can choose the object, that should get the message.
The existing block, that sends messages as broadcast could remain of course.
Perhaps other people would like this option, too?
Regards, Thomas Karp
broadcast [ v]Just don't do the latter for non-selected sprites.
when I receive [ v]
- dracae
-
Scratcher
1000+ posts
Sending messages to one object instead of broadcast
Or you can use “for this sprite only” variables.
- kb_kl
-
New Scratcher
1 post
Sending messages to one object instead of broadcast
Hi,
I think, its a good idea to send messages to one object only. Here a concrete example:
Suppose you develop a sprite that represents a traffic light. Then - to have more of them - you copy the sprite and give them different names. So you have different objects with just the same behaviour. In the present version of Scratch there is no mechanism, to activate these objects separately. With the suggestion of tomkarp, it would be possible to activate a specific object by just the same message.
Regards, Klaus Becker
I think, its a good idea to send messages to one object only. Here a concrete example:
Suppose you develop a sprite that represents a traffic light. Then - to have more of them - you copy the sprite and give them different names. So you have different objects with just the same behaviour. In the present version of Scratch there is no mechanism, to activate these objects separately. With the suggestion of tomkarp, it would be possible to activate a specific object by just the same message.
Regards, Klaus Becker
- Zro716
-
Scratcher
1000+ posts
Sending messages to one object instead of broadcast
Hi,I'm sure with the existing blocks nearly everything can be worked around. In fact, what you are describing is a scenario which clones would make perfect use of. Just give one sprite all three costumes for a traffic light, plus a global variable named “Signal color” (or anything you like).
I think, its a good idea to send messages to one object only. Here a concrete example:
Suppose you develop a sprite that represents a traffic light. Then - to have more of them - you copy the sprite and give them different names. So you have different objects with just the same behaviour. In the present version of Scratch there is no mechanism, to activate these objects separately. With the suggestion of tomkarp, it would be possible to activate a specific object by just the same message.
Suppose on startup of the project you want to create all three lights at once. To save room for more clones, I'm using an example that creates only two other from the parent sprite. If you want to take it a step further see this.
when green flag clickedNow that you have the three lights of a signal, you can use just one broadcast for all purposes:
set [Signal color v] to [1] //for keepsake
go to x: (100) y: (100) //wherever the signal is
set costume to [green v] //has to be first costume, next costumes are "yellow" then "red"
create clone of [myself v]
when I start as a clone //this is what the clone of the sprite does once it is created
change y by (20) //move the signal component up a little
next costume //switches to the next costume (i.e. "red" to "yellow", then "yellow" to "green")
if <(costume #) < [3]> then
create clone of [myself v] //recursion at its best
end
when I receive [signal v]
if <(costume #) = (Signal color)> then //either one of the clones or parent sprite receives the message
set [brightness v] effect to (50) //lighting up the signal
if <(costume #) = [2]> then //if it's a yellow light, we don't wait as long as the other lights!
wait (5) secs
else
wait (10) secs
end
set [brightness v] effect to (0) //signal turns off
set [Signal color v] to (((Signal color) mod (3)) + (1)) //change to the next light or back to the first
broadcast [signal v] //this is where the single broadcast is needed to complete the cycle
end
- tomkarp
-
New Scratcher
2 posts
Sending messages to one object instead of broadcast
Thank you for your suggestions.
But as I am a teacher, my approach is not to think of a problem and then think of how I (or the students) can
solve this problem.
The first question is: “What concept do I want to teach?” Then I create a problem that can be be solved
by using the concept I want to introduce.
So, when I want to teach objectoriented thinking, I need the opportunity to send messages to a certain
object, because this is the way you do it on objectoriented languages.
I know I can solve any problem like that in Scratch, when an objects only listens to the messages, that should
be recieved from the object (like Blaze349 mentioned). But this is not the way you would do it
in Java or (nearly?) any other OO-language.
So, the question here is: Do other people think this feature would be useful?
The question is not: How can I get problem XY to work?
Regards, Thomas
But as I am a teacher, my approach is not to think of a problem and then think of how I (or the students) can
solve this problem.
The first question is: “What concept do I want to teach?” Then I create a problem that can be be solved
by using the concept I want to introduce.
So, when I want to teach objectoriented thinking, I need the opportunity to send messages to a certain
object, because this is the way you do it on objectoriented languages.
I know I can solve any problem like that in Scratch, when an objects only listens to the messages, that should
be recieved from the object (like Blaze349 mentioned). But this is not the way you would do it
in Java or (nearly?) any other OO-language.
So, the question here is: Do other people think this feature would be useful?
The question is not: How can I get problem XY to work?
Regards, Thomas
- Firedrake969
-
Scratcher
1000+ posts
Sending messages to one object instead of broadcast
Using a broadcast to a specific sprite is almost the same, if not pretty similar, as doing sprite.function(), IMO.
If you think of a clone as an individual object inheriting from its parent, then you can actually teach how the object-specific function works by using the workaround.
If you think of a clone as an individual object inheriting from its parent, then you can actually teach how the object-specific function works by using the workaround.
Last edited by Firedrake969 (July 6, 2014 20:07:17)
- Blaze349
-
Scratcher
1000+ posts
Sending messages to one object instead of broadcast
Thank you for your suggestions.How about…
But as I am a teacher, my approach is not to think of a problem and then think of how I (or the students) can
solve this problem.
The first question is: “What concept do I want to teach?” Then I create a problem that can be be solved
by using the concept I want to introduce.
So, when I want to teach objectoriented thinking, I need the opportunity to send messages to a certain
object, because this is the way you do it on objectoriented languages.
I know I can solve any problem like that in Scratch, when an objects only listens to the messages, that should
be recieved from the object (like Blaze349 mentioned). But this is not the way you would do it
in Java or (nearly?) any other OO-language.
So, the question here is: Do other people think this feature would be useful?
The question is not: How can I get problem XY to work?
Regards, Thomas
(var)//local variable
//when you want to broadcast
set [var v] to [1]
//In the other sprite
if <([var v] of [Sprite1 v]) = [1]> then
end
Last edited by Blaze349 (July 7, 2014 00:31:02)
- Discussion Forums
- » Suggestions
-
» Sending messages to one object instead of broadcast




