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

#1 2012-06-10 07:14:28

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

How to fix your scripts- The complete guide

Have you ever made a script do do something, but when you play it, something goes wrong? Then you look at your scripts and you just can't see what's wrong. It should work perfectly. But it doesn't. Here, I've collected the most common problems I encounter when making a script, and I'll tell you how to get around these problems.

Delays
These blocks can cause delays in scripts.

wait () secs
wait until <>
repeat until <>
play sound [. v] until done
say [] for () secs
think [] for () secs
glide () secs to x: () y: ()
When these are used, the ENTIRE script will be held up until these actions are completed. For example:
when gf clicked
forever
if <key [up arrow v] pressed?>
next costume
wait (0.2) secs
end
if <key [right arrow v] pressed?>
change x by (5)
In this script, the right arrow is used to move.
If the Up Key is pressed, the sprite will change costumes making an animation. There will be a short pause between each costume change so that the animation is visible.

However, the 0.2 second wait will affect the entire script. This means that while the animation is running, the sprite will be unable to move until the 0.2 seconds are up. This will make movement jolty. (I know this isn't the best example, but I hope you see what I mean)

HOW TO FIX THIS
The simplest way is to break this into 2 separate scripts. So the above script would become
when gf clicked
forever
if <key [up arrow v] pressed?>
next costume
wait (0.2) secs
when gf clicked
forever
if <key [right arrow v] pressed?>
change x by (5)
This is why 1s1s projects are exceptionally impressive.

Double-Scripting
This is when you include 2 contradicting blocks. For example, in the same sprite you might include
 change [variable v] by [10] 
and
 set [variable v] to [100] 
It might seem at first that this sort of stuff will never happen, and very few people do this, but actually, this is one of the most common problems I've seen. You could forget that you put one of those blocks there and forgot to remove it.

TO FIX THIS you just have to carefully double-check every sprite in you project if it's a "For every Sprite" variable or just for the subject sprite if it's a "For this sprite only" variable. NOTE: I only talk about variables but the same thing applies to the
 change x by (5) 
and the
 set x to (5) 
Colour Sensing
this applies to the blocks,
 <touching color [#000000]?> 
and
 <color [#FFFFFF] is touching [#000000]?> 
If sensing isn't working, all I can say is double-check you have the right colours. Be careful if you use the effect blocks
 change [color v] effect by (5) 
 change [brightness v] effect by (5) 
 change [ghost v] effect by (5) 
as you would need to adjust the colours in the sensing blocks to match this. You can use this block to reset the effects:
 clear graphic effects 
Where possible, use the block
 <touching [sprite1 v]?> 
Using the = Sign
Look at this platformer script:
forever
if <touching [star v]?>
change [score v] by [5]
end
if <touching [coin v]?>
change [score v] by [1]
end
if <(score)=[100]>
say [You Win!!!]
So you play the game, collecting stars and coins but the sprite never says that you win. You look at the score and it's 126, so surely you've won by now and the sprite should say so. But no. Because the sprite will only say so if score=100 but score never did =100. You could have gotten 6 coins and then gotten 24 stars, meaning that the score was 96, then 101 but never 100 itself. See the problem?

TO FIX THIS use this block instead.
 
if <(score) > [99]>
say [You Win!!!]
Pen not working?
The pen only draws on the background so if there's a sprite in the way, the pen markings will only show underneath the sprite, on the background. There's no real way to fix this, but at least you know what the problem is.

I hope I've explained things clearly and if there are any other common problems or glitches, tell me  smile

Last edited by PhirripSyrrip (2012-06-11 16:07:29)


http://i46.tinypic.com/ao03lk.png

Offline

 

#2 2012-06-10 07:22:36

Reflect
New Scratcher
Registered: 2012-05-06
Posts: 29

Re: How to fix your scripts- The complete guide

Nice Guide. Very helpful  smile

Offline

 

#3 2012-06-10 23:19:54

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: How to fix your scripts- The complete guide

repeat (10) can also delay scripts.

Offline

 

#4 2012-06-10 23:57:10

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: How to fix your scripts- The complete guide

You might want to also mention the "clear graphic effects" block...I've started to find it very useful when I'm dealing with color, brightness, and ghost all at the same time.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#5 2012-06-11 16:04:50

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: How to fix your scripts- The complete guide

chanmanpartyman wrote:

repeat (10) can also delay scripts.

I suppose but only by a fraction of a second. It only really messes things up if the repeat (10) block is combined with the blocks I listed above.


http://i46.tinypic.com/ao03lk.png

Offline

 

#6 2012-06-11 16:08:11

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: How to fix your scripts- The complete guide

AtomicBawm3 wrote:

You might want to also mention the "clear graphic effects" block...I've started to find it very useful when I'm dealing with color, brightness, and ghost all at the same time.

ok  wink  I forgot about that

Last edited by PhirripSyrrip (2012-06-15 11:33:10)


http://i46.tinypic.com/ao03lk.png

Offline

 

#7 2012-06-16 07:29:50

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: How to fix your scripts- The complete guide

PhirripSyrrip wrote:

AtomicBawm3 wrote:

You might want to also mention the "clear graphic effects" block...I've started to find it very useful when I'm dealing with color, brightness, and ghost all at the same time.

ok  wink  I forgot about that

Sorry, I hardly use it, almost forgot it existed!


http://i46.tinypic.com/ao03lk.png

Offline

 

Board footer