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

#1 2007-05-26 02:49:13

Ginger_Overlord
Scratcher
Registered: 2007-05-17
Posts: 11

Forever?

Hi All,

If there is an operation in your script which is executed 'forever' how do you stop it?

I've tried 'stop script' but this is ignored and 'stop all' and this stops EVERYTHING (obviously!).

Any answers - greatly appriciated,

G_O.

Offline

 

#2 2007-05-26 04:01:04

Mick
Scratcher
Registered: 2007-03-23
Posts: 100+

Re: Forever?

You should use the "forever if _" block.


Go to www.legoless.com
It's my blog.  big_smile

Offline

 

#3 2007-05-26 05:19:43

Ginger_Overlord
Scratcher
Registered: 2007-05-17
Posts: 11

Re: Forever?

Hi Mick,

So if I wanted to repeat an operation 'continuosly' (or forever) but only for certain length of time, how would I set up my script?

Example -

When 'flag' clicked
wait 10 secs
Forever
Change Y by -5
Wait 0.5 secs
Change Y by 5
Wait 0.5

How would I be able to perform the above 'forever' section of the script for only a certain lengh of time?

Cheers,

G_O.

Offline

 

#4 2007-05-26 06:09:46

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Forever?

Ginger,

Stop Script should get you out of a forever loop. Are you sure it's ever getting to the Stop Script blocK?

Here's how I would repeat something for a particular amount of time, in this case five seconds (assume I've created a variable called StopTime):

set StopTime to Timer + 5
Repeat until Timer > StopTime
  Change Y by -5
  etc.

Offline

 

#5 2007-05-26 13:31:22

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

Re: Forever?

My advice is to use the forever block only very sparingly.  There is a good reason why the repeat-until construct (and slight variants)  is more common in programming languages!

Offline

 

#6 2007-05-26 17:29:22

mres
Scratch Team
Registered: 2007-03-08
Posts: 48

Re: Forever?

Here is a slight variation of what weissjd suggested (but without variables):

reset timer
repeat-until timer > 5
   change y by 5
   etc.

Offline

 

Board footer