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 endhow do i fix this?
Offline
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 endIf that doesn't work, link me the project, and I might be able to help.
Last edited by 7734f (2013-03-24 17:53:44)
Offline
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) endIf that doesn't work, link me the project, and I might be able to help.
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
Offline
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 pressedis unsatisfactory. i was wondering if there is another method (like a switch statement) or if this problem only exists with my computer.
Offline
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