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

#1 2012-08-21 20:30:49

DolphinSwarm
Scratcher
Registered: 2011-07-05
Posts: 38

Left + Right Arrow Key Help.

All right, I have a script that changes the X-Position by 3 if the right arrow key is pressed and one that changes the X-Position by -3 if the left arrow key is pressed on my sprite. The sprite runs when one if these keys is clicked and stops when it is released, going into an idle pose. But when I press both, the character's costume twitches between the standing costume and running one while jerking around. How do I solve this problem? Help would be greatly appreciated.


http://s11.postimg.org/gj2ejsx0f/Dolphin_Swarm_Composing.jpg

Offline

 

#2 2012-08-21 20:34:25

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

Re: Left + Right Arrow Key Help.

Use something like this:

if <<[left arrow v] key pressed?> and <not <[right arrow v] key pressed?>>>
 your script
else
 if <[right arrow v] key pressed?>
  your script
 end
end

Last edited by ErnieParke (2012-08-21 20:36:57)


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

Offline

 

#3 2012-08-21 20:53:45

DolphinSwarm
Scratcher
Registered: 2011-07-05
Posts: 38

Re: Left + Right Arrow Key Help.

It kind of worked, the only problem is he runs backwards whenever i press the right key then the left one.


http://s11.postimg.org/gj2ejsx0f/Dolphin_Swarm_Composing.jpg

Offline

 

#4 2012-08-21 21:18:41

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Left + Right Arrow Key Help.

I think it's better to have:

when gf clicked
forever
if <key [left arrow v] pressed?>
your script
end
if <key [right arrow v] pressed?>
your script.
end
end
That should work a little better. It's also a bit more professional and traditional.  smile

Last edited by henley (2012-08-21 21:18:56)


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#5 2012-08-22 16:47:38

DolphinSwarm
Scratcher
Registered: 2011-07-05
Posts: 38

Re: Left + Right Arrow Key Help.

well... yes, that's my original script, but he only problem is that if i press both keys, he remains stationary, yet he makes a running animation.


http://s11.postimg.org/gj2ejsx0f/Dolphin_Swarm_Composing.jpg

Offline

 

#6 2012-08-22 17:12:01

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

Re: Left + Right Arrow Key Help.

DolphinSwarm wrote:

It kind of worked, the only problem is he runs backwards whenever i press the right key then the left one.

Is there some way for you to post all of your movement script or upload your project? That would help a lot.


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

Offline

 

#7 2012-08-22 17:16:47

DolphinSwarm
Scratcher
Registered: 2011-07-05
Posts: 38

Re: Left + Right Arrow Key Help.

Well, i'm not good with scratchblocks in the forums, but here it is: http://scratch.mit.edu/projects/DolphinSwarm/2741980


http://s11.postimg.org/gj2ejsx0f/Dolphin_Swarm_Composing.jpg

Offline

 

#8 2012-08-22 18:17:45

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Left + Right Arrow Key Help.

if <<key [left arrow v] pressed?> and <key [right arrow v] pressed?>>
use whatever script you want to make the sprite stand still or do the idle animation, or whatever
end
That should help with the animation problem.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#9 2012-08-22 19:01:44

DolphinSwarm
Scratcher
Registered: 2011-07-05
Posts: 38

Re: Left + Right Arrow Key Help.

all right, thanks. I've tried that already, but I'll se how it goes.


http://s11.postimg.org/gj2ejsx0f/Dolphin_Swarm_Composing.jpg

Offline

 

#10 2012-08-22 19:17:13

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Left + Right Arrow Key Help.

Oh,and make sure it looks like this:

if <<key [left arrow v] pressed?> and <not<key [right arrow v] pressed?>>>
move left
end
if <<key [right arrow v] pressed?> and <not<key [left arrow v] pressed?>>>
move right
end
if <<key [left arrow v] pressed?> and <key [right arrow v] pressed?>>
don't move and use standstill costume/animation
end


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#11 2012-08-26 18:18:41

maxamillion321
Scratcher
Registered: 2011-06-17
Posts: 500+

Re: Left + Right Arrow Key Help.

when gf clicked
if <key [right arrow pressed v]?>
move (10) steps

Last edited by maxamillion321 (2012-08-26 18:20:19)

Offline

 

#12 2012-08-26 18:46:50

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: Left + Right Arrow Key Help.

if <key [right arrow v] pressed?>
   move right
else
if <key [left arrow v] pressed?>
   move left
end
end


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#13 2012-08-27 08:30:42

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Left + Right Arrow Key Help.

Molybdenum wrote:

if <key [right arrow v] pressed?>
   move right
else
if <key [left arrow v] pressed?>
   move left
end
end

This ahas already been suggested, and ruled out.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#14 2012-08-27 08:33:39

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Left + Right Arrow Key Help.

I think this topic is resolved, anyways.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

Board footer