Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help in broadcast messages
- HaziqZaidaan
-
New Scratcher
1 post
Help in broadcast messages
I was currently making a scratch project(https://scratch.mit.edu/projects/676675317) it involved broadcasts a lot and I saw that some messages were broadcast once and some constantly executes themselves. This problem me a lot so can anyone tell me why it happens, I would truly appreciate it.
- Lawnmowersarefast
-
Scratcher
9 posts
Help in broadcast messages
Could you reshare it? then i could see what's wrong and maybe fix it in a remix.
Last edited by Lawnmowersarefast (April 29, 2022 16:03:13)
- deck26
-
Scratcher
1000+ posts
Help in broadcast messages
Are you broadcasting in a loop? Which broadcasts are a problem and what runs the broadcast block?
- deck26
-
Scratcher
1000+ posts
Help in broadcast messages
uhh. the project isn't there…Remove the close bracket from the link.
- dave3m
-
Scratcher
500+ posts
Help in broadcast messages
When your snake clone first hits the wall, you hide your main snake and send the event applehide. You then continue your forever loop to keep testing the same condition. This condition remains true until your player clicks Respawn.
Since you haven't reset the position of the snake sprite or stopped its movement, it will stay hidden while still touching the wall. It will also try to keep moving into the wall – if you were to reset its position without setting X Movement and Y Movement to 0, it will continue moving until it hits a wall again. The hidden snake will also continue to generate clones after the game ends.
Since the sprite is still touching the wall, it will repeatedly send the applehide event over and over again in its forever loop.
There are different ways to fix this.
- It is probably a good idea to stop the movement of the main snake sprite when the game ends and to reset its position so that it is no longer touching a wall. This will prevent it sending the applehide event more than once.
- You may also want to reset length to 0. This would ensure that any new clones delete themselves quickly, but this won't stop the snake from continuing to generate clones.
- You may also want to have the snake's movement2 loop(s) end when the snake hits the wall (e.g. using a variable and testing for it to end the loop). This is to stop moving the snake / responding to direction commands and also to stop generating new clones.
Since you haven't reset the position of the snake sprite or stopped its movement, it will stay hidden while still touching the wall. It will also try to keep moving into the wall – if you were to reset its position without setting X Movement and Y Movement to 0, it will continue moving until it hits a wall again. The hidden snake will also continue to generate clones after the game ends.
Since the sprite is still touching the wall, it will repeatedly send the applehide event over and over again in its forever loop.
There are different ways to fix this.
- It is probably a good idea to stop the movement of the main snake sprite when the game ends and to reset its position so that it is no longer touching a wall. This will prevent it sending the applehide event more than once.
- You may also want to reset length to 0. This would ensure that any new clones delete themselves quickly, but this won't stop the snake from continuing to generate clones.
- You may also want to have the snake's movement2 loop(s) end when the snake hits the wall (e.g. using a variable and testing for it to end the loop). This is to stop moving the snake / responding to direction commands and also to stop generating new clones.
Last edited by dave3m (May 1, 2022 05:41:39)
- Discussion Forums
- » Help with Scripts
-
» Help in broadcast messages