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

#1 2010-12-25 03:53:51

nisarg_shah
New Scratcher
Registered: 2010-12-25
Posts: 1

Made a nice little catch-me-if-you-can game, but there's a bug...

Hi guys, here's my project at: http://scratch.mit.edu/projects/nisarg_shah/1499975
But the problem here is that the timer doesn't stop at 0. Please help me out guys!

Thanks in advance,
Nisarg Shah

Offline

 

#2 2010-12-25 05:10:35

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Made a nice little catch-me-if-you-can game, but there's a bug...

O_o It looks correct, so why is it messing up?  hmm

Though I notice that in the experimental viewer the number's a bit off (so it wouldn't work there)... but what about the actual Scratch program?

EDIT: Here's a bit of stuff I found - maybe this has something to do with it:

TheSuccessor wrote:

ScratchReallyROCKS wrote:

It's just computer number inaccuracy. I don't fully understand it, but I know it's not specifically a Scratch glitch. It even happens in other programming languages.

It's because computers store numbers in binary. Integers can be translated perfectly, but decimals are different. ½ in binary = 0.1, and ¼ = 0.01, 3/8 = 0.011 and 5/8 = 0.101. Mathematical people might begin to see the pattern now. 1/3 in binary = 0.0101 recurring. This is converted back from 0.0101010101 (or however many digits your computer stores it to) as 1/4 + 1/16 + 1/64 + 1/256 + 1/1024. This comes to 0.333007812.
Your computer will do it more accurately as it stores the binary number to many more decimal places. Some numbers though, are particularly difficult to store in binary, and so, when the computer rounds the number, once it has been converted back, incorrectly, these errors creep in. [/longBoringLectureOnMaths]

Last edited by Jonathanpb (2010-12-25 05:12:09)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#3 2010-12-25 05:18:32

deatheater
Scratcher
Registered: 2008-04-11
Posts: 1000+

Re: Made a nice little catch-me-if-you-can game, but there's a bug...

Change the

repeat until timer = 0

to

repeat until timer < 0

Offline

 

Board footer