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

#1 2010-08-01 13:49:31

dmaisells
New Scratcher
Registered: 2010-08-01
Posts: 1

Handling inter-sprite processing

Is there any tutorial or literature to read on processing between sprites?  I wanted to write all of the logic on my stage and reference the other sprites but apparently I don't see how to reference a sprite and take action on it from the main stage coding area.  So basically I wrote a program with my son which uses loops in the main stage and also in the sprites.  The loops share global variables between them and act on them inside the loops. 

Programming like this is not so straightsforward.  There is no GoEvents statements as there is in VB6 to tell the OS to stop executing a loop temporarily and let the OS handle any user initiated events (e.g., from the other sprites).   Without this statement, how do forever loops in multiple sprites interact?  Is each loop guaranteed to execute at a single point in time - in other words, am I guaranteed the the main loop will only execute once and the sprite loops not execute two or three times before the main loop gets to the bottom of the loop.

Scratch is a great program to learn programming without having to learn an underlying language but there are still some fundamental rules that need going over: e.g.,
- Can multiple sprites have a loop that starts when green flagged pressed?  What are recommendations?
- Can a loop be momentarily stopped by the user to allow the OS to execute a loop from another sprite to allow it to set data before the loop in question continues to execute?
- Can code from another sprite be called from the stage for example?
Thanks

Offline

 

#2 2010-08-01 14:02:43

m71134
Scratcher
Registered: 2010-03-03
Posts: 1000+

Re: Handling inter-sprite processing

This topic might help you a little bit:
http://scratch.mit.edu/forums/viewtopic.php?id=161

Offline

 

#3 2010-08-01 14:06:06

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Handling inter-sprite processing

dmaisells wrote:

- Can multiple sprites have a loop that starts when green flagged pressed?  What are recommendations?
- Can a loop be momentarily stopped by the user to allow the OS to execute a loop from another sprite to allow it to set data before the loop in question continues to execute?
- Can code from another sprite be called from the stage for example?

1) Yes. You just have to make a separate script in each sprite that has a loop block after the [when green flag clicked] block.

2) In a way, yes. For example, say the data from the sending sprite was stored in a variable called 'data'. In the receiving sprite, inside it's loop would be a [wait until <not <data = 0> >] block. This means that the receiving sprite would wait until it gets data from the sending sprite before it executes the rest of it's code.

3) Sorry, but this isn't possible in Scratch. Instead, try this modified version of Scratch called BYOB, which gives you the ability to make your own blocks, and has some added features like, what you want, the ability to call scripts and single blocks. You can download it here


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

Board footer