Discuss Scratch

inom5962dojo
Scratcher
100+ posts

Variable changing too much

I’ve created the following script:

when I receive [ Hide v]
repeat (6)
wait (.1) secs
change [Hide v] by (1)
end

Instead of counting up to 6, it counts by 7s, 6 times.

Last edited by inom5962dojo (Feb. 7, 2023 00:10:08)

legendary34678
Scratcher
1000+ posts

Variable changing too much

The only thing I can think of is that Hide is being broadcasted multiple times. Could you post the link to your project so that we can see the actual code?
inom5962dojo
Scratcher
100+ posts

Variable changing too much

legendary34678 wrote:

The only thing I can think of is that Hide is being broadcasted multiple times. Could you post the link to your project so that we can see the actual code?

Yeah, here: https://scratch.mit.edu/projects/798180775/
legendary34678
Scratcher
1000+ posts

Variable changing too much

Each of the clones you create will receive the Hide broadcast message and run that script individually. I'm assuming you have five clones and one sprite that are each running the loop, so that's why it seems like it's running six times. You could solve this by having the backdrop receive the broadcast because it doesn't have any clones.
inom5962dojo
Scratcher
100+ posts

Variable changing too much

legendary34678 wrote:

Each of the clones you create will receive the Hide broadcast message and run that script individually. I'm assuming you have five clones and one sprite that are each running the loop, so that's why it seems like it's running six times. You could solve this by having the backdrop receive the broadcast because it doesn't have any clones.

Thank you!
inom5962dojo
Scratcher
100+ posts

Variable changing too much

legendary34678 wrote:

Each of the clones you create will receive the Hide broadcast message and run that script individually. I'm assuming you have five clones and one sprite that are each running the loop, so that's why it seems like it's running six times. You could solve this by having the backdrop receive the broadcast because it doesn't have any clones.

Now the main sprite isn’t hiding.

Last edited by inom5962dojo (Feb. 6, 2023 19:29:53)

medians
Scratcher
1000+ posts

Variable changing too much

inom5962dojo wrote:

legendary34678 wrote:

Each of the clones you create will receive the Hide broadcast message and run that script individually. I'm assuming you have five clones and one sprite that are each running the loop, so that's why it seems like it's running six times. You could solve this by having the backdrop receive the broadcast because it doesn't have any clones.

Now the main sprite isn’t hiding.
You can create a broadcast to hide the sprite or you can put the code in the sprite and instead use sprite only variables to check if the sprite is running the clone or if the clones are. This can be done since:

If you had this code with a sprite only variable, the sprite would have a value of 0 while the clones would have 1. This works with sprite only lists as well. You can use this to check it after then and put the already existing code in the check.

Last edited by medians (Feb. 7, 2023 00:07:53)

inom5962dojo
Scratcher
100+ posts

Variable changing too much

medians wrote:

inom5962dojo wrote:

legendary34678 wrote:

Each of the clones you create will receive the Hide broadcast message and run that script individually. I'm assuming you have five clones and one sprite that are each running the loop, so that's why it seems like it's running six times. You could solve this by having the backdrop receive the broadcast because it doesn't have any clones.

Now the main sprite isn’t hiding.
You can create a broadcast to hide the sprite or you can put the code in the sprite and instead use sprite only variables to check if the sprite is running the clone or if the clones are. This can be done since:

If you had this code with a sprite only variable, the sprite would have a value of 0 while the clones would have 1. This works with sprite only lists as well. You can use this to check it after then and put the already existing code in the check.

Turns out I had the clone script repeating 6 times when there was only code for 5, fixing that fixed it.

Powered by DjangoBB