Discuss Scratch

fun19567
Scratcher
57 posts

Sending broadcasts to clones or masters.

when I receive [ v] and [ v]
broadcast [ v] to [ v]

Suggestions for blocks, second input in when I receive is to select sprites, clones or masters.

Hi I'm a fellow Scratcher who loves history!
Please follow me!
And Check out RPG Stoneborn here : https://scratch.mit.edu/projects/680492862/
Thanks



cs3868895
Scratcher
1000+ posts

Sending broadcasts to clones or masters.

_nix wrote:

delete all of [who's receiving sing along v] :: list
add [Dee] to [who's receiving sing along v]
create clone of [ sprite v]
add [Devin] to [who's receiving sing along v]
create clone of [ sprite v]
add [Sam] to [who's receiving sing along v]
create clone of [ sprite v]
add [Scratch Cat] to [who's receiving sing along v]
create clone of [ sprite v]
broadcast [sing along v]

when I start as a clone
if <[who's receiving sing along v] contains [Scratch Cat]> then
set [pitch v] effect to (0) :: sound
repeat (3)
play sound [Meow v] until done
change [pitch v] effect by (20) :: sound
end
This may take me…
Forever to make code blocks
But I did make an edited version of a workaround it might work idk-

Fish more ideas
I'm Fishy a cis bi female.
sorry, but as of currently, I'm moving platforms, I can't handle the drama.



fun19567
Scratcher
57 posts

Sending broadcasts to clones or masters.

cs3868895 wrote:

(#2)

_nix wrote:

delete all of [who's receiving sing along v] :: list
add [Dee] to [who's receiving sing along v]
create clone of [ sprite v]
add [Devin] to [who's receiving sing along v]
create clone of [ sprite v]
add [Sam] to [who's receiving sing along v]
create clone of [ sprite v]
add [Scratch Cat] to [who's receiving sing along v]
create clone of [ sprite v]
broadcast [sing along v]

when I start as a clone
if <[who's receiving sing along v] contains [Scratch Cat]> then
set [pitch v] effect to (0) :: sound
repeat (3)
play sound [Meow v] until done
change [pitch v] effect by (20) :: sound
end
This may take me…
Forever to make code blocks
But I did make an edited version of a workaround it might work idk-

HUH, this is out of place?

Hi I'm a fellow Scratcher who loves history!
Please follow me!
And Check out RPG Stoneborn here : https://scratch.mit.edu/projects/680492862/
Thanks



cs3868895
Scratcher
1000+ posts

Sending broadcasts to clones or masters.

_nix wrote:

broadcast message1 to only sprite1

Method 1: broadcast to one sprite (thanks, @yavuz61035!)

Set a variable to the name of the sprite you want to respond. Broadcasts are always received by every sprite, so every place where you use “when I receive” with that message, check if the variable matches the name of that sprite:

ask [Who's going to dance next?] and wait
set [who's receiving do a cool dance v] to (answer)
broadcast [do a cool dance v] and wait
play sound [Hooray! v] until done

when I receive [do a cool dance v] // in Gobo's code
if <(who's receiving do a cool dance) = [Gobo]> then
point in direction (45 v)
repeat (4)
repeat (10)
move (10) steps
end
turn cw (90) degrees
end
end

when I receive [do a cool dance v] // in Tera's code
if <(who's receiving do a cool dance) = [Tera]> then
set rotation style [left-right v]
repeat (5)
point in direction (90 v)
glide (1) secs to x: (50) y: (100)
point in direction (-90 v)
glide (1) secs to x: (50) y: (-50)
end
end
It's generally best if you use a different variable for each “targeted” broadcast. That way, if you broadcast two or more different messages at the same time, you'll make sure each message gets where it's going!

Method 2: broadcast to 2+ specific sprites at the same time

It's not possible to broadcast one message twice in the same Scratch frame—it'll just be received once. So if you want to broadcast to two specific sprites, you'll have to use a list:

delete all of [who's receiving sing along v] :: list
add [Dee] to [who's receiving sing along v]
add [Devin] to [who's receiving sing along v]
add [Sam] to [who's receiving sing along v]
add [Scratch Cat] to [who's receiving sing along v]
broadcast [sing along v]

when I receive [sing along v]
if <[who's receiving sing along v] contains [Scratch Cat]> then
set [pitch v] effect to (0) :: sound
repeat (3)
play sound [Meow v] until done
change [pitch v] effect by (20) :: sound
end
end
Method 3: without stopping/restarting broadcasts

Keep in mind that if you broadcast something which sprites are already responding to right now, Scratch will interrupt and restart all the “when I receive” scripts with the same message. If you want to make sure the sprites who already started keep going after you broadcast the message again (maybe to another sprite), you can use a variable and the “wait until” or “forever…if” blocks.

when I receive [join the team v]
if <(who's joining the team) = [Pico]> then
set [part of the team v] to [true] // local variable, "for this sprite only"
end

when green flag clicked
set [part of the team v] to [false]
wait until <(part of the team) = [true]>
forever
... follow the leader ... :: grey
end
I'm sorry (,: if you want the full workaround quote here you go-

Fish more ideas
I'm Fishy a cis bi female.
sorry, but as of currently, I'm moving platforms, I can't handle the drama.



fun19567
Scratcher
57 posts

Sending broadcasts to clones or masters.

Thanks a lot! I'll be needing this for my upcoming biggest project!

Hi I'm a fellow Scratcher who loves history!
Please follow me!
And Check out RPG Stoneborn here : https://scratch.mit.edu/projects/680492862/
Thanks



Powered by DjangoBB