Discuss Scratch

TacoBellStudios
Scratcher
5 posts

Broadcast script not working

I have a broadcast message block. But for some reason, it's not broadcasting. I can manually do it and the scripts connected to the message broadcast will work, yet when I run my project, the block doesn't broadcast the message. Any ideas?

Project Link
ballyrag
Scratcher
100+ posts

Broadcast script not working

Which broadcast?
RokCoder
Scratcher
1000+ posts

Broadcast script not working

I assume you mean it's never broadcasting “Scene 5” from “Scene 4”? The reason for this is that you're broadcasting “Scene 4” in a forever loop. Each time you broadcast a message, its receivers start their scripts from the beginning. This means the receiver for “Scene 4” is continually restarting and never reaches the part where it broadcasts “Scene 5”.

This is the forever loop I'm talking about -

set [Clone ID v] to (1)
forever
if <(Clone ID) = (0)> then
broadcast [Scene 4 v]
delete this clone

This code is running from the master sprite (rather than a clone) so “delete this clone” does nothing here. If you want that script to stop executing after the broadcast then try this -

set [Clone ID v] to (1)
wait until <(Clone ID) = (0)>
broadcast [Scene 4 v]
TacoBellStudios
Scratcher
5 posts

Broadcast script not working

RokCoder wrote:

I assume you mean it's never broadcasting “Scene 5” from “Scene 4”? The reason for this is that you're broadcasting “Scene 4” in a forever loop. Each time you broadcast a message, its receivers start their scripts from the beginning. This means the receiver for “Scene 4” is continually restarting and never reaches the part where it broadcasts “Scene 5”.

This is the forever loop I'm talking about -

set [Clone ID v] to (1)
forever
if <(Clone ID) = (0)> then
broadcast [Scene 4 v]
delete this clone

This code is running from the master sprite (rather than a clone) so “delete this clone” does nothing here. If you want that script to stop executing after the broadcast then try this -

set [Clone ID v] to (1)
wait until <(Clone ID) = (0)>
broadcast [Scene 4 v]
I tried that and boom, it works now! Thanks! Also, the delete clone block is so that the clones also disappear at the same time as the original sprite, basically a transition to the next part.
RokCoder
Scratcher
1000+ posts

Broadcast script not working

TacoBellStudios wrote:

Also, the delete clone block is so that the clones also disappear at the same time as the original sprite, basically a transition to the next part.
As mentioned, that delete is doing absolutely nothing as it's in the code for the master sprite and not the clones. Those clones aren't being deleted - they're just being ghosted out so you can't see them. Add a delete this clone block to the end of the ghosting script if you want the clones to be deleted properly.
TacoBellStudios
Scratcher
5 posts

Broadcast script not working

RokCoder wrote:

TacoBellStudios wrote:

Also, the delete clone block is so that the clones also disappear at the same time as the original sprite, basically a transition to the next part.
As mentioned, that delete is doing absolutely nothing as it's in the code for the master sprite and not the clones. Those clones aren't being deleted - they're just being ghosted out so you can't see them. Add a delete this clone block to the end of the ghosting script if you want the clones to be deleted properly.
If that's the case, then I would've mentioned it already, but apparently, the clones are being deleted anyway. If I add the delete clone block to the clone script, the actions that would be caused based on the Clone ID system wouldn't work, since there are no clones to follow the code.
RokCoder
Scratcher
1000+ posts

Broadcast script not working

TacoBellStudios wrote:

If that's the case, then I would've mentioned it already, but apparently, the clones are being deleted anyway. If I add the delete clone block to the clone script, the actions that would be caused based on the Clone ID system wouldn't work, since there are no clones to follow the code.

The clones weren't being deleted and the suggestion to delete them after ghosting them to invisibility was made to fix that issue (as that's what this forum is for). I have no idea why you left the previous response when I was helping you but I see you used the offered solution anyway. Maybe close this post now that the issue is fixed.

Last edited by RokCoder (June 9, 2024 12:26:43)

Powered by DjangoBB