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

#1 2010-04-06 18:28:40

Razion
Scratcher
Registered: 2010-04-06
Posts: 2

Velocity issues.

In a script for movement(velocity), I have a section for left movement and right movement. They're set up the same, but for some reason right movement doesn't work.

The part of the script for left and right is:

If key right arrow pressed
          set xVel 1
else
          set xVel 0

if key left arrow pressed
          set xVel -1
else
          set xVel 0

change x by xVel


This should work...? Any help would be appreciated.


Edit:

Apparently, whichever I put first in the script is the one that works.

Last edited by Razion (2010-04-06 18:33:40)

Offline

 

#2 2010-04-06 19:23:21

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Velocity issues.

That's a tricky one to spot  smile . Here is what you are basically saying. (Let's pretend that the right arrow key is pressed). The right arrow key is pressed, so we are going to set velocity to one. BUT WAIT, afterwards there is an if else statment that says if the left arrow key isn't pressed (which it isn't) then set it to 0! So our 1 value just got reset, back to 0. Here is what it should look like:

<when green flag clicked>
<forever>
<if><key[ right arrow ]pressed?>
<set{ velocity }to( 1
<else>
    <if><key[ left arrow ]pressed?>
    <set{ velocity }to( -1
    <else>
        <set{ velocity }to( 0

I hope this helped!

Offline

 

#3 2010-04-06 19:44:09

Razion
Scratcher
Registered: 2010-04-06
Posts: 2

Re: Velocity issues.

Perfekt! Fatastisch! [insert another exclamatory here]

Exactly what I needed. Works like a charm. :]

Thanks much!

Offline

 

#4 2010-04-07 05:14:39

mathematics
Scratcher
Registered: 2009-03-01
Posts: 1000+

Re: Velocity issues.

Next time put this kind of topic in the All About Scratch forum.

Offline

 

Board footer