Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need help with a bug I found
- SandwichCafe
-
Scratcher
100+ posts
Need help with a bug I found
The Bug is where if you spawn a crate multiple times (In the spawn menu when you click the create) More and more will appear then it is supposed to. It is meant to spawn one crate, not 20 creates when you click the crate in the spawn menu 5 times.
My friend tried fixing it but it did not work
I uploaded it on my alt account
Here is the link: https://scratch.mit.edu/projects/455922414/

My friend tried fixing it but it did not work
I uploaded it on my alt account
Here is the link: https://scratch.mit.edu/projects/455922414/
Last edited by SandwichCafe (Nov. 28, 2020 09:00:51)
- awesome-llama
-
Scratcher
1000+ posts
Need help with a bug I found
When a broadcast is sent, it can be received by anything. That includes clones. The cloned crates are also able to react to the spawn broadcast and they will clone themselves too. If you have multiple clones already spawned, then a single broadcast may get you multiple clones spawned at once.
The best way to prevent this is to just make sure the broadcast receive hat also checks if it is a clone or not. Two common ways involve costume detection and local variables.
The costume way involves a costume that the original sprite will always be set to and a costume that the clones will always use. When a clone is created, set to the clone costume. When a broadcast is received, check which costume the sprite/clone is. If it is set to the original costume, it is the original sprite and it will clone itself.
The other way is similar, but instead of storing the status as a costume, store this in a local variable (the ones that are unique to each clone, don't be confused by the default global variable). The original sprite may be set to 0, the clones when created are set to 1. Check if it is 0 and if so, the sprite is original and it can clone itself.
The best way to prevent this is to just make sure the broadcast receive hat also checks if it is a clone or not. Two common ways involve costume detection and local variables.
The costume way involves a costume that the original sprite will always be set to and a costume that the clones will always use. When a clone is created, set to the clone costume. When a broadcast is received, check which costume the sprite/clone is. If it is set to the original costume, it is the original sprite and it will clone itself.
The other way is similar, but instead of storing the status as a costume, store this in a local variable (the ones that are unique to each clone, don't be confused by the default global variable). The original sprite may be set to 0, the clones when created are set to 1. Check if it is 0 and if so, the sprite is original and it can clone itself.
- SandwichCafe
-
Scratcher
100+ posts
Need help with a bug I found
When a broadcast is sent, it can be received by anything. That includes clones. The cloned crates are also able to react to the spawn broadcast and they will clone themselves too. If you have multiple clones already spawned, then a single broadcast may get you multiple clones spawned at once.
The best way to prevent this is to just make sure the broadcast receive hat also checks if it is a clone or not. Two common ways involve costume detection and local variables.
The costume way involves a costume that the original sprite will always be set to and a costume that the clones will always use. When a clone is created, set to the clone costume. When a broadcast is received, check which costume the sprite/clone is. If it is set to the original costume, it is the original sprite and it will clone itself.
The other way is similar, but instead of storing the status as a costume, store this in a local variable (the ones that are unique to each clone, don't be confused by the default global variable). The original sprite may be set to 0, the clones when created are set to 1. Check if it is 0 and if so, the sprite is original and it can clone itself.
Oh, that makes sense now, going to remind me that later
Last edited by SandwichCafe (Nov. 28, 2020 09:33:15)
- Discussion Forums
- » Help with Scripts
-
» Need help with a bug I found

