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

#1 2013-03-24 17:38:06

cauzality
New Scratcher
Registered: 2013-03-19
Posts: 44

little bug... big problems (basic movement)

i was trying to make more natural looking motion controlled by a keyboard and had a problem... which is even more a problem when considering multiple players:

PROBLEM: if i hit two keys at once, scratch thinks one of the keys remains down (even after i let up) until i hit it again.

many of the guides i looked at here have the same problem:
http://scratch.mit.edu/forums/viewtopic.php?id=88043

here's an example of the code with this bug (at least on my machine):

forever
   if <key [w v] pressed?>
      change y by (speed)
   end
   if <key [a v] pressed?>
      change x by ([-1] * (speed))
   end
   if <key [s v] pressed?>
      change y by ([-1] * (speed))
   end
   if <key [d v] pressed?>
      change x by (speed)
   end
end
how do i fix this?

Offline

 

#2 2013-03-24 17:52:51

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: little bug... big problems (basic movement)

Try writing your script like this:

forever
 change y by (yspeed)
 change x by (xspeed)
 if <key [w v] pressed?>
  change [yspeed v] by 1
 end
 if <key [s v] pressed?>
  change [yspeed v] by -1
 end
 if <key [a v] pressed?>
  change [xspeed v] by -1
 end
 if <key [d v] pressed?>
  change [xspeed v] by 1
 end
end
If that doesn't work, link me the project, and I might be able to help.  smile

EDIT: The variable blocks are supposed to be orange, sorry!

Last edited by 7734f (2013-03-24 17:53:44)


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#3 2013-03-24 18:00:35

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: little bug... big problems (basic movement)

7734f wrote:

Try writing your script like this:

forever
 change y by (yspeed)
 change x by (xspeed)
 if <key [w v] pressed?>
  change [yspeed v] by (1)
 end
 if <key [s v] pressed?>
  change [yspeed v] by (-1)
 end
 if <key [a v] pressed?>
  change [xspeed v] by (-1)
 end
 if <key [d v] pressed?>
  change [xspeed v] by (1)
 end
If that doesn't work, link me the project, and I might be able to help.  smile

EDIT: The variable blocks are supposed to be orange, sorry!

Fixed; there isn't supposed to be an end at the end of a forever loop, and you forgot ()'s around your numbers.

With regards,

ErnieParke


http://i46.tinypic.com/35ismmc.png

Offline

 

#4 2013-03-24 18:48:12

cauzality
New Scratcher
Registered: 2013-03-19
Posts: 44

Re: little bug... big problems (basic movement)

that's more like what i'm actually trying... i just put a simple version so i wouldn't have to type more.

i think the problem is with the chain of if statements. but using

when [any v] key pressed
is unsatisfactory. i was wondering if there is another method (like a switch statement) or if this problem only exists with my computer.

i haven't used this method in a posted project because of this failure. i could make one if you'd like but would rather not. just let me know. thanks.

Offline

 

#5 2013-03-24 19:35:29

cauzality
New Scratcher
Registered: 2013-03-19
Posts: 44

Re: little bug... big problems (basic movement)

nevermind...

i realized my problem was bigger than i thought, any key would lock up my controls even if i hadn't programmed it to do anything. i uploaded a pong example to my account to show you and it turns out it works just fine on this site... just not on my ubuntu machine. i don't know what's going on but i think there isn't a problem with the script.

thank you anyway.

Offline

 

Board footer