This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-01-19 15:46:43

bramp
Scratcher
Registered: 2010-01-19
Posts: 3

Concurrency problem. Lost broadcast?

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

 

#2 2010-01-19 17:10:11

RHY3756547
Scratcher
Registered: 2009-08-15
Posts: 1000+

Re: Concurrency problem. Lost broadcast?

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

 

#3 2010-01-19 18:20:07

bramp
Scratcher
Registered: 2010-01-19
Posts: 3

Re: Concurrency problem. Lost broadcast?

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

 

#4 2010-01-19 22:03:28

cds56
Scratcher
Registered: 2008-05-02
Posts: 500+

Re: Concurrency problem. Lost broadcast?

perhaps use a "wait until" block.


http://img192.imageshack.us/img192/909/meowdevlogo.pnghttp://i32.tinypic.com/pucti.png

Offline

 

#5 2010-01-20 10:48:44

everythingRhymes
Scratcher
Registered: 2009-12-03
Posts: 100+

Re: Concurrency problem. Lost broadcast?

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

 

#6 2010-01-20 15:09:30

MyRedNeptune
Community Moderator
Registered: 2007-05-07
Posts: 1000+

Re: Concurrency problem. Lost broadcast?

Dictionary wrote:

Concurrent: taking place, existing, or running parallel at the same time


http://i52.tinypic.com/5es7t0.png I know what you're thinking! "Neptune! Get rid of those filthy advertisements and give us back the Zarathustra siggy, you horrible person!" Well, don't worry about it, the Zara siggy will be back soon, new and improved! ^^ Meanwhile, just do what the sig tells you to. >.>

Offline

 

#7 2010-01-20 15:14:01

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Concurrency problem. Lost broadcast?

Could you upload the project to the Scratch site? Then I may be able to help you.

Offline

 

#8 2010-01-21 07:00:01

Ace-of-Spades
Scratcher
Registered: 2010-01-08
Posts: 1000+

Re: Concurrency problem. Lost broadcast?

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.


11110010100011010100011010101000100011011011001010111100101000110101000110101010001000110110110010101111001010001101010001101010100010001101101100101011110010100011010100011010101000100011011011001010
110101010010001010101010101010101010101010100110101010010101010010101001101011010101010010101010101

Offline

 

#9 2010-01-21 12:23:44

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Concurrency problem. Lost broadcast?

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.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#10 2010-02-10 12:22:33

Jlessig
Scratcher
Registered: 2009-11-05
Posts: 1

Re: Concurrency problem. Lost broadcast?

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?

Offline

 

#11 2010-02-10 12:49:13

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Concurrency problem. Lost broadcast?

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.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#12 2010-02-10 16:10:38

Ace-of-Spades
Scratcher
Registered: 2010-01-08
Posts: 1000+

Re: Concurrency problem. Lost broadcast?

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.


11110010100011010100011010101000100011011011001010111100101000110101000110101010001000110110110010101111001010001101010001101010100010001101101100101011110010100011010100011010101000100011011011001010
110101010010001010101010101010101010101010100110101010010101010010101001101011010101010010101010101

Offline

 

Board footer