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

#1 2010-05-16 13:57:38

E-RAY444
Scratcher
Registered: 2010-05-16
Posts: 5

Key Press Scripting Help

I need help making a script where when you press a key (in this case the D key) it triggers something but when you let go of the D key the thing it triggered stopped and if you press D again the trigger starts again, I need this for a one on one fighting game. Can someone please help me?

Offline

 

#2 2010-05-16 14:03:37

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Key Press Scripting Help

if d key pressed
W
H
E
N

P
R
E
S
S
E
D

C
O
D
E
else (if not d key pressed)
W
H
E
N

N
O
T

P
R
E
S
S
E
D

C
O
D
E

--------------------------------------


You can now reach me on Twitter @johnnydean1_

Offline

 

#3 2010-05-16 14:03:46

E-RAY444
Scratcher
Registered: 2010-05-16
Posts: 5

Re: Key Press Scripting Help

Ok, I got that actual part down but when I press the key the thing it triggers moves really REALLY fast, for instance, I want to make someone move forward and animate to look like he's walking, I have the animate part right, but when I press D (which is supposed to make him move) he moves forward but the animation moves about 5x faster than it should. Any help?

Offline

 

#4 2010-05-16 14:03:53

Wolfie1996
Retired Community Moderator
Registered: 2009-07-08
Posts: 1000+

Re: Key Press Scripting Help

I think I get what you're trying to say. Try this script:

[blocks]
<when green flag clicked>
<forever>
<if><key[ D ]pressed?>
<repeat until><<  <not> <key[ D ]pressed?> >>
DO SOMETHING
<end>
<else>
DO SOMETHING ELSE
<end>
<end>
[/blocks]

Let me know if this isn't what you're looking for - I hope this helps  smile

EDIT: Just read your latest post - try adding a:

[blocks]
<wait(  )secs>
[/blocks]

To your script...

EDIT2: The end of the block came out the wrong colour  sad

Last edited by Wolfie1996 (2010-05-16 14:06:29)


"...Jargon - the practice of never calling a spade a spade, when you might instead call it a manual earth-restructing implement..." - Bill Bryson, Mother Tongue

Offline

 

#5 2010-05-16 14:12:34

E-RAY444
Scratcher
Registered: 2010-05-16
Posts: 5

Re: Key Press Scripting Help

I got this in there already
<wait(  )secsc>
because when i take out the key press script and make it where when the game starts hes doing that animation, it works prefectly and with perfect timing, but when i add the key press scripts is when it messes up because in order to make him move properly the part needs to be:
wait 0.1 secs

Last edited by E-RAY444 (2010-05-16 14:13:38)

Offline

 

#6 2010-05-16 14:15:35

E-RAY444
Scratcher
Registered: 2010-05-16
Posts: 5

Re: Key Press Scripting Help

NEVER MIND FIXED!

Turns out i had a script that didnt need to be there

Offline

 

Board footer