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

#1 2011-12-01 03:55:21

EricAndJeff
New Scratcher
Registered: 2011-11-06
Posts: 5

concurrency question

I read the post by johnm about concurrency from 2007:

http://scratch.mit.edu/forums/viewtopic.php?id=8130
johnm said: "It [Scratch] runs as many commands as it can until it gets to the end of the innermost loop. If it doesn't hit a loop, Scratch simply runs the rest of the blocks in the stack."

MY QUESTION is if there's a way to force a script (or a portion of a script) to run through without being interrupted?  -assuming that it DOES have loops.

So for example, say I have ten sprites, and each one has a script that includes loops.  I'd like each script to run through completely before the next script is executed.

I could put each script in a forever loop and have a wait until [it's my turn] at the top.  The script whose turn it is would run for a while and then execution would go to the other scripts but would quickly return to the desired one.  This doesn't seem ideal.

Or I could put each script under a unique "when I receive" block.  Then some other script could "broadcast and wait" each unique message in sequence.  But I want all ten scripts to run many times per second - so I'm not sure if the broadcast method is best.

I will test these two options, but I'm hoping there's a trick to force a section of a script (including loops) to run all way through.

Thank you for any help you can give me.
Jeff

Offline

 

#2 2011-12-01 09:22:13

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: concurrency question

If you have something loop a fixed number of times, you can duplicate the content of the loop the number of times is loops and get rid of the loop completely, but other than that, the only way to do this in Scratch is to run the Scratch project in the flash player with turbo mode.


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#3 2011-12-01 11:07:41

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: concurrency question

Scratch does thread switches at the end of loops, so you'll have to find some workaround for your problem.

Offline

 

#4 2011-12-01 12:16:00

EricAndJeff
New Scratcher
Registered: 2011-11-06
Posts: 5

Re: concurrency question

Thank you.
(I was afraid of that.)

Offline

 

Board footer