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.
waitsecs
wait until
repeat until
play sound. ▼until done
sayforsecs
thinkforsecs
When these are used, the ENTIRE script will be held up until these actions are completed. For example:glidesecs to x:y:
In this script, the right arrow is used to move.whenclicked
foreverifkeyup arrow ▼pressed?next costumewait0.2secsifkeyright arrow ▼pressed?change x by5
This is why 1s1s projects are exceptionally impressive.whenclicked
foreverifkeyup arrow ▼pressed?next costumewait0.2secswhenclicked
foreverifkeyright arrow ▼pressed?change x by5
andchangevariable ▼by10
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.setvariable ▼to100
and thechange x by5
Colour Sensingset x to5
andtouching color ?
If sensing isn't working, all I can say is double-check you have the right colours. Be careful if you use the effect blockscolor is touching ?
changecolor ▼effect by5
changebrightness ▼effect by5
as you would need to adjust the colours in the sensing blocks to match this. You can use this block to reset the effects:changeghost ▼effect by5
Where possible, use the blockclear graphic effects
Using the = Signtouchingsprite1 ▼?
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?foreveriftouchingstar ▼?changescore ▼by5iftouchingcoin ▼?changescore ▼by1ifscore=100sayYou Win!!!
Pen not working?ifscore>99sayYou Win!!!
Last edited by PhirripSyrrip (2012-06-11 16:07:29)
Offline
repeat (10) can also delay scripts.
Offline
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.
Offline
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.
Offline
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 I forgot about that
Last edited by PhirripSyrrip (2012-06-15 11:33:10)
Offline
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
I forgot about that
Sorry, I hardly use it, almost forgot it existed!
Offline