Hi,
I'm new to Scratch and I imagine I might be doing something wrong, but I think I've hit a concurrency issue, and I wanted to understand the internals a bit better.
I have 3 sprites on the screen which concurrently spin changing their costumes a random number of times. When each sprite has finished they call broadcast. In my stage I have something waiting for that broadcast and it decrements a value, then checks if that value is zero and contains. The idea is that some code runs only after all the sprites have finished spinning.
The problem is that most of the time the "when I receive" gets called three times, but sometimes it only gets called twice. I validated this by adding a item to a list each time it is called, and sometimes it ends up with 3 items, and other times with 2. So my question is how do the broadcasts work? Do you lose a broadcast if you are currently handling a previous one?
thanks
Offline
If you broadcast when a broadcast script of the same kind is still running, then that broadcast will restart it's script. It seems that your problem is happening because the animations of the concurrently spinning sprites are broadcasting at different times.
Offline
Thanks for your reply RHY3756547. Yes my sprites are broadcasting at different times, a random time in fact.
I'm unsure the script is restarting, instead it seems to not be running. I say this because the very first block adds a to a list as a debugging mechanism. It seems only 2 items are being added to my list instead of three.
Either way, I think I'll have to restructure my code.
Offline
bramp wrote:
Hi,
I'm new to Scratch and I imagine I might be doing something wrong, but I think I've hit a concurrency issue, and I wanted to understand the internals a bit better.
I have 3 sprites on the screen which concurrently spin changing their costumes a random number of times. When each sprite has finished they call broadcast. In my stage I have something waiting for that broadcast and it decrements a value, then checks if that value is zero and contains. The idea is that some code runs only after all the sprites have finished spinning.
The problem is that most of the time the "when I receive" gets called three times, but sometimes it only gets called twice. I validated this by adding a item to a list each time it is called, and sometimes it ends up with 3 items, and other times with 2. So my question is how do the broadcasts work? Do you lose a broadcast if you are currently handling a previous one?
thanks
it might help if you defined concurrency for me because i- i mean these other guys don't know what it means.
Offline
Dictionary wrote:
Concurrent: taking place, existing, or running parallel at the same time
Offline
Actually it should be working fine unless you're using variables as the broadcasts. But don't listen to me, I've never used 3 broadcasts at once. Only 81 at once.
Offline
i agree with ace-of-spades, just exchange the broadcast with change variable blocks. And have a script on the stage waiting untill the variable is at 0.
Offline
Jlessig wrote:
I am new to Scatch as well and made my Stage, but realized I need it to actually be a Sprite.
Is there a way to change the Stage into a Sprite?
2 things,
1. this should be in all about scratch.
2. Go into costumes, right click (Or hold left) and click "turn into new sprite" it will become and new sprite, then click and drag the rest of the costumes (If there are more) onto the new sprites thumbnail, then you'll have to edit them to take out the white backgrounds, but you will be ok.
Offline
If you shift click on the screen or right-click, there'll be a menu choice that says 'Grab Screen Image for new sprite', which you can then use to drag a box around the screen.
Offline