Discuss Scratch

ImArabat
Scratcher
21 posts

When I receive broadcast for clone?

I think that there should be a way for clones to receive a broadcast signal. I know that I could do it with variables, but that takes a bit.
Example: If I have a level game that generates terrain by duplicating a “master” sprite, and I want it to generate new terrain once I finish the level, I can't
just have something like this: (When I start as a clone)
(forever)
(if) (I receive broadcast “?”)
(do something)
Anyone agree?
djdolphin
Scratcher
1000+ posts

When I receive broadcast for clone?

when I receive [ v]
works for clones…
Scratchifier
Scratcher
1000+ posts

When I receive broadcast for clone?

Use a private variable, clonetype. Set it to something before you make a clone, then set it to something like “mainsprite” after making a clone. Like this:

set [clonetype v] to [playershadow ]
create clone of [myself v]
set [clonetype v] to [playerarm ]
create clone of [myself v]
set [clonetype v] to [main ]

Then, for the clone loop, you can do something like this:

when I start as a clone
if <(clonetype) = [playershadow]> then

forever
etc ::custom
end

end
if <(clonetype) = [playerarm]> then

forever
etc ::custom
end

end

And therefore it will work for broadcasts:

when I receive [yay! v]
if <(clonetype) = [playershadow]> then
only the player shadow sprite will be able to do things in this if statement. ::custom
The other two *playerarm clone and main sprite* will find this if statement false :: custom
because the clonetype value is different for both of them, presuming that it is a private variable. ::custom
end
BookDoggy
New Scratcher
8 posts

When I receive broadcast for clone?

Use multiple sprites?
kvackkvack
Scratcher
500+ posts

When I receive broadcast for clone?

Just have a private variable named “clone?” that is set to 1 when a clone is created and 0 in the main script.
When you want a broadcast for clones, just check if “clone” is set to 1 and if it is, run the script.
when I receive [... v]
if <(clone?) = [1]> then
...
end
Or, if you wanna be more specific, use what @Scratchifier said.
TheSillyClown
Scratcher
27 posts

When I receive broadcast for clone?

IDK,all i know is that i have 14 messages right now
kittiesrule247
Scratcher
100+ posts

When I receive broadcast for clone?

YES YES YES I SUPPORT
EIephant_Lover
Scratcher
500+ posts

When I receive broadcast for clone?

No support, this block would be extremely ambiguous, it's practically already rejected (very similar to the "broadcast received?" suggestion).

Easy workaround:
when I start as a clone
set [clone? v] to [1] // Local variable
when green flag clicked
set [clone? v] to [0]
create clone of [myself v]
broadcast [message1 v]
when I receive [message1 v]
if <(clone?) = [0]> then
... // this is for the original sprite
else
... // this is for all clones
end

Get it?

Last edited by EIephant_Lover (Oct. 6, 2019 18:55:53)

hedgehog_blue
Scratcher
1000+ posts

When I receive broadcast for clone?

TheSillyClown wrote:

IDK,all i know is that i have 14 messages right now
This topic is about how to make clones behave differently than the sprite when they receive a message. You might have posted in the wrong place.

EIephant_Lover wrote:

when I start as a clone
set [clone? v] to [1] // Local variable
when I receive [message1 v]
if <(clone?) = [1]> then
... // this is for the original sprite
else
... // this is for all clones
end
I think you put the comments the in wrong order. According to your code, the if true is for the clones and the else is for the sprites, but your comments say it is the opposite.
EIephant_Lover
Scratcher
500+ posts

When I receive broadcast for clone?

hedgehog_blue wrote:

TheSillyClown wrote:

IDK,all i know is that i have 14 messages right now
This topic is about how to make clones behave differently than the sprite when they receive a message. You might have posted in the wrong place.

EIephant_Lover wrote:

when I start as a clone
set [clone? v] to [1] // Local variable
when I receive [message1 v]
if <(clone?) = [1]> then
... // this is for the original sprite
else
... // this is for all clones
end
I think you put the comments the in wrong order. According to your code, the if true is for the clones and the else is for the sprites, but your comments say it is the opposite.
Yep, you're right. I think what happened was that I had it as clone? = 0, then I thought I messed that up, and changed it to 1, which was actually wrong XD
minimonkey0102
Scratcher
1 post

When I receive broadcast for clone?

ImArabat wrote:

I think that there should be a way for clones to receive a broadcast signal. I know that I could do it with variables, but that takes a bit.
Example: If I have a level game that generates terrain by duplicating a “master” sprite, and I want it to generate new terrain once I finish the level, I can't
just have something like this: (When I start as a clone)
(forever)
(if) (I receive broadcast “?”)
(do something)
Anyone agree?
I agree it is easier that way
popzprim
Scratcher
7 posts

When I receive broadcast for clone?

I have a problem but its quite different i have a sprite but i what the broadcasts to only effect the clone not the main sprite can any of you help
jaked27797
Scratcher
40 posts

When I receive broadcast for clone?

when I start as a clone
forever
if <(foo) = [1]> then
etc.
end
end
LOJMOSESrobloxplayer
Scratcher
28 posts

When I receive broadcast for clone?

when I start as a clone
if <<(Broadcast name) = [True]>> then
What you want the broadcast to do to the clone
end

when I receive [Broadcast name v]
What you want the broadcast to do
set [Broadcast name v] to [True]

Last edited by LOJMOSESrobloxplayer (Aug. 8, 2022 05:02:21)

jakvan86068
Scratcher
1 post

When I receive broadcast for clone?


thanks!! i needed that help

Last edited by jakvan86068 (Feb. 13, 2025 14:33:36)

medians
Scratcher
1000+ posts

When I receive broadcast for clone?

Maybe we could just have a clone id block that reports 0 if it isn't a clone? Then you'd be able to do:
when I receive [message v]
if <(clone id) > [0]> then
...
end
or:
when I receive [message v]
if <(clone id) = [1]> then
...
end
jmb1293634
Scratcher
1000+ posts

When I receive broadcast for clone?

popzprim wrote:

I have a problem but its quite different i have a sprite but i what the broadcasts to only effect the clone not the main sprite can any of you help
use
when I start as a clone
set [is clone v] to [1]
when green flag clicked
set [is clone v] to [0]
when I receive [ v]
if <(is clone) = [1]> then
...
end
10goto10
Scratcher
1000+ posts

When I receive broadcast for clone?

This is one of the pitfalls of Scratch programming (it’s number 9 in my pitfalls studio). I don’t think that they need to change the design of Scratch but there is an opportunity to give beginners a quick heads up.

We all know how clones work but if you’re starting out and you notice that clones do not get cloned copies of the scripts in their running state then it is pretty easy to think that the events must have also been disabled.

Powered by DjangoBB