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

#1 2008-02-20 15:14:46

pkeenan
Scratcher
Registered: 2007-09-14
Posts: 7

Order of scripts

When you have multiple spirits and each has a script that starts with "when flag is clicked" - which runs first or do all run at the same time?

Offline

 

#2 2008-02-20 15:24:26

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Order of scripts

They run in parallel, i.e. all at the same time.


Jens Mönig

Offline

 

#3 2008-02-20 17:27:03

Heybrian
Scratcher
Registered: 2007-12-05
Posts: 100+

Re: Order of scripts

Ugh. This is what i hate most. They all start at the same time but when i have two or more  complicated scripts working at the same time one dosnt work. sadface.


Black Mesa. go here to get a game 10 times better than SN or FW.  http://scratch.mit.edu/galleries/view/10650
Smiley! copy and paste these into your post or signature!  smile   sad    yikes                 big_smile     wink    tongue    hmm    neutral   cool   lol   mad   roll

Offline

 

#4 2008-02-20 19:39:44

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Order of scripts

They start in an arbitrary order that is not guaranteed to be the same each time, so if you need one thing to happen before another, you must put in some explicit synchronization.

The two most common forms of synchronization are putting in waits and using broadcasts.

For example, if script A must finish before B starts and B finish before C starts you could do.


when greenflag clicked
    ...body of A....

when greenflag clicked
    wait 0.1 seconds
    ...body of B...

when greenflag clicked
    wait 0.2 seconds
    ....body of C....

You'd have to adjust the times to make sure that everything in A is done before B starts and everything in B is done before C starts.

It is a little easier to use broadcasts:

when greenflag clicked
    ...stuff in A that must come before B...
    broadcast start B
    ...rest of A....

when I receive start B
    ...stuff in B that must come before C...
    broadcast start C
    ...rest of B...

when I receive start C
    ...body of script C...

Offline

 

Board footer