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

#1 2012-10-27 12:09:12

Maxmanrules1
New Scratcher
Registered: 2012-10-27
Posts: 1

Rounding Error in Variables

In a program I made, I used variables to represent the x and y coordinates of some sprite, for example, when x = 1 and y = 2, go to (60, 120). When you press the arrow keys, these values will change by Integers and so will the sprite's x and y position. For some reason, however, doing this would sometimes result in situations like x = 3.846298569837 x 10^(-16) which is very very close to 0, but it still threw my program off quite a bit. I fixed it with a rounding script, but I'm still not sure whether this is my error or Scratch's.

Offline

 

#2 2012-10-27 15:20:55

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Rounding Error in Variables

Could you give us a link to the project so we can see what's going on here?

Offline

 

#3 2012-10-28 07:31:59

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Rounding Error in Variables

It happens because scratch pixels don't exactly overlap with screen pixels, so x and y positions adjust themselves automatically to pixels they can  display themselves on. It only happens with x and y not other variables and usually the difference is too small to matter, and when it is, you can just use round.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

Board footer