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

#1 2007-07-01 08:32:28

ScipioBellorum
Scratcher
Registered: 2007-05-15
Posts: 94

What am I doing wrong?

I am trying to make an object move to a certain set of points if pointing in the correct direction. So far, my script is like this:

When UP ARROW key is pressed
If <DIRECTION = 0>
Glide 2 secs to X:50 Y:50
If <DIRECTION = 90>
Glide 2 secs to X:100 Y:100
If <DIRECTION = 180>
Glide 2 secs to X:150 Y:150

etc.

It looks fine to me but for some reason whenever I press UP the object doesn't move. Any ideas about what I'm doing wrong?

Also, how can I download Scratch 1.1 without wiping my existing files. I don't want a full installation just and incrimental one.

Last edited by ScipioBellorum (2007-07-01 08:42:20)


http://img393.imageshack.us/img393/339/logory8.png
                      The word processor for Scratch

Offline

 

#2 2007-07-01 09:26:30

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: What am I doing wrong?

Looks like it should work, the only thing that springs to mind is if you are already in that location...

Try uploading the project so we can have a look.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2007-07-01 09:36:19

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: What am I doing wrong?

It half works for me!

e.g. the script responds if the direction is 90 or -90 but the if statements are ignored if the direction is 0, 180 or -180

Looks like a bug.

regards

Simon

Offline

 

#4 2007-07-01 10:11:25

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: What am I doing wrong?

Update - if I insert a "point in direction" block at the start - all if statements work.

The 0, 180,-180 statements only fail if I manually turn the sprite in the area above the script work area.

regards

Simon

Offline

 

#5 2007-07-01 11:11:00

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: What am I doing wrong?

Ahh - probably means your manual turns were not *exactly* to 0,180 etc.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#6 2007-07-01 14:16:33

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: What am I doing wrong?

@Mayem

Try it on your computer and see if you can do any better :-)

Even with Direction being displayed on the stage and indicating 0.0 or -180.0, the if statements don't get executed.


regards

Simon

Offline

 

#7 2007-07-01 17:38:55

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

Re: What am I doing wrong?

One should never do equality tests for floating point numbers.  Instead one should test a range of numbers.  For example

if abs(direction - 90) < 45 then ....

Offline

 

#8 2007-07-01 23:11:46

DrJim
Scratcher
Registered: 2007-05-26
Posts: 100+

Re: What am I doing wrong?

Converting to an integer by using the "round" block before doing the test should also work.

Offline

 

#9 2007-07-02 03:20:18

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: What am I doing wrong?

I think we need 2 forums - one for PhD Computer Science people and one for the proletariat :-)

I just think ScipioBellorum has just unearthed  a little issue that could do with dealing with by the Scratch team. :-)

i.e

Some directions can seemingly be set manually to integers, others can't.

Or as Kevin points out, some directions can be successfully compared to integers but others can't. :-)

Also, while playing with this problem, I've noticed that you can't set direction to be 180 manually either -  when pointing down its set to -180.  This doesn't match up with the default suggested direction for down as being 180.

regards

Simon

Offline

 

#10 2007-07-02 07:52:53

natalie
Scratch Team
Registered: 2007-03-07
Posts: 100+

Re: What am I doing wrong?

I see what you mean about rotating manually to 180 and it only registering as -180. And therefore not triggering the "if" statement! I agree to be consistent it should default to 180 not -180.

Also, about manually rotating to 0 and it looking like 0 but probably being stored in the computer with decimal points, so therefore not equaling 0.

I will suggest that Scratch should only store direction as an integer--do you all think that makes sense?

In the meantime, you could use

for up (manually rotated to 0)
       "if (direction < 1) and (direction > -1)"
     
for down (manually rotated to -180)
        "if (direction < -179) and (direction > -181)"

Offline

 

#11 2007-07-02 08:10:55

natalie
Scratch Team
Registered: 2007-03-07
Posts: 100+

Re: What am I doing wrong?

If you wanted to be really comprehensive for down, so that it worked for 180 or -180, you could use:

    "if (direction < -179) and (direction > -181)  OR  if (direction < 181) and (direction > 179)"

But I realize that's terribly long!

Offline

 

#12 2007-07-02 11:54:29

DrJim
Scratcher
Registered: 2007-05-26
Posts: 100+

Re: What am I doing wrong?

natalie wrote:

I will suggest that Scratch should only store direction as an integer--do you all think that makes sense?

My first thought is that with your relatively small screen, you're going to get some pretty funny paths if you do anything with the direction parameter and it only has integer values.  However I haven't played with this much so it might be OK.

Offline

 

#13 2007-07-02 12:44:07

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

Re: What am I doing wrong?

I think that direction should *not* be rounded to an integer---it is much easier for the programmer to put in round(direction)=90 than to try to recover the values that got rounded into oblivion.  "Point towards <sprite>" should be done to full precision.

Incidentally, direction does round in squeak (bad) but not in java (last time I checked, which was back around v11 or so).

A different issue is what directions can be manually set.  The hand rotation interface should probably round, since it is only for approximate positioning, and hand accuracy is not that great.  Rounding to the nearest degree (or even nearest 5 degrees) may be fine.

Offline

 

#14 2007-07-02 15:08:38

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: What am I doing wrong?

I will suggest that Scratch should only store direction as an integer--do you all think that makes sense?

Since the problem only seems to occurs if you set direction manually, then I'd suggest leaving direction as a floating point number otherwise I imagine a few projects might not function as well as before.

If you set direction in a script to be 0 or -180, then an "if direction=0" or "if direction =-180" seem to work fine which all points towards it being a problem with the manual direction and not a real problem with comparing integers to floating points.

regards

Simon

Offline

 

#15 2007-07-02 17:23:49

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: What am I doing wrong?

Indeed - you can only turn the sprite manually in programing mode, anyway.  This is a very isolated error.

At the most, fix the manual direction changer so that it operates to teh nearest degree, but please don't change the whole programs ability to operate to decimal places of a degree.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#16 2007-07-02 19:25:22

natalie
Scratch Team
Registered: 2007-03-07
Posts: 100+

Re: What am I doing wrong?

Okay, I definitely take back that suggestion about rounding to an integer for direction! That's a good idea to just have the manual rotation round off, if possible.

Offline

 

Board footer