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

#1 2009-05-23 16:09:03

Dudeson
Scratcher
Registered: 2009-05-07
Posts: 25

button pressed repeatedly

hi! i have a little problem. (idk if this is the right place to post this...)

how do i make something happen when i press a button repeatedly? (btw, im pretty good at scratch. So dont think i couldnt code anything by myself^^)

For example:

I want my character to bash when i press the left arrow key twice. How should i make that??

Offline

 

#2 2009-05-23 16:23:03

SmartIrishKid
Scratcher
Registered: 2008-07-19
Posts: 1000+

Re: button pressed repeatedly

[blocks]<when[ left arrow ]key pressed>
<reset timer>
<wait until> << <( <timer> <>> 1 )> <or> <key[ left arrow ]pressed?> >>
<if> <key[ left arrow ]pressed?>
(Code for Bash)
[/blocks]
The blocks didn't turn out right, but I hope that helps!


Discuss future Scratch RPGs, online games, and more!

Offline

 

#3 2009-05-23 16:45:59

DawnLight
Scratcher
Registered: 2009-04-25
Posts: 500+

Re: button pressed repeatedly

Dudeson wrote:

hi! i have a little problem. (idk if this is the right place to post this...)

how do i make something happen when i press a button repeatedly? (btw, im pretty good at scratch. So dont think i couldnt code anything by myself^^)

For example:

I want my character to bash when i press the left arrow key twice. How should i make that??

This is in the right topic! SmartIrishKid gave you the right code.

Offline

 

#4 2009-05-24 09:03:20

Dudeson
Scratcher
Registered: 2009-05-07
Posts: 25

Re: button pressed repeatedly

thank you ALL SO MUCH! i'll try it soon out! thx!!!

Offline

 

#5 2009-05-24 13:50:17

Dudeson
Scratcher
Registered: 2009-05-07
Posts: 25

Re: button pressed repeatedly

SmartIrishKid wrote:

[blocks]<when[ left arrow ]key pressed>
<reset timer>
<wait until> << <( <timer> <>> 1 )> <or> <key[ left arrow ]pressed?> >>
<if> <key[ left arrow ]pressed?>
(Code for Bash)
[/blocks]
The blocks didn't turn out right, but I hope that helps!

hmmm.. my game will be 2 players.. can is there no way to make every object have its own timer? or do i have to code it???

Offline

 

#6 2009-05-25 05:52:25

Dudeson
Scratcher
Registered: 2009-05-07
Posts: 25

Re: button pressed repeatedly

btw, it doesnt work! it will bash even if i hold the button... idk.. maybe im just stupid.. i didnt have much time to check it out really good.. i'll try again today.

Offline

 

#7 2009-05-25 08:16:12

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: button pressed repeatedly

Dudeson wrote:

btw, it doesnt work! it will bash even if i hold the button... idk.. maybe im just stupid.. i didnt have much time to check it out really good.. i'll try again today.

You're not stupid, just inexperienced  tongue

Here's something that might solve it well:

[blocks]<when[ left ]key pressed>
<repeat until><( <{ TIMER_VARIABLE }> <=> 1 )>
<wait until><not> <key[ left ]pressed?> >> --This could prevent a horrible glitch when holding the key
<if><< <key[ left ]pressed?> <and> <( <{ TIMER_VARIABLE }> <=> 0 )> >>
[insert bash script here]
<stop script>
<end>
<end>

<when[ left ]key pressed>
<set{ TIMER_VARIABLE }to( 0
<wait( 0.5 )secsc> --You can change this.
<set{ TIMER_VARIABLE }to( 1
[/blocks]

I hope that helped.


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#8 2009-05-25 09:31:21

MyRedNeptune
Community Moderator
Registered: 2007-05-07
Posts: 1000+

Re: button pressed repeatedly

Actually, this belongs in All About Scratch... Troubleshooting is for bugs/glitches, while All About Scratch is for asking questions.  smile

This script should work:
[blocks]<when[ left arrow ]key pressed>
<set{ key press valid? }to( 1
<wait until> <not> <key[ left arrow ]pressed?> >>
<repeat until> <( <{ key press valid? }> <=> 0 )>
<if> <key[ left arrow ]pressed?>
<wait until>   <not> <key[ left arrow ]pressed?> >>
.....[Bash script]
<wait until>   <not> <key[ left arrow ]pressed?> >>
<stop script>
<end>
<end>

<when[ left arrow ]key pressed>
<wait( 1 )secsc>
<set{ key press valid? }to( 0[/blocks]


Scratch on!


http://i52.tinypic.com/5es7t0.png I know what you're thinking! "Neptune! Get rid of those filthy advertisements and give us back the Zarathustra siggy, you horrible person!" Well, don't worry about it, the Zara siggy will be back soon, new and improved! ^^ Meanwhile, just do what the sig tells you to. >.>

Offline

 

#9 2009-05-29 16:13:55

Dudeson
Scratcher
Registered: 2009-05-07
Posts: 25

Re: button pressed repeatedly

MyRedNeptune wrote:

Actually, this belongs in All About Scratch... Troubleshooting is for bugs/glitches, while All About Scratch is for asking questions.  smile

This script should work:
[blocks]<when[ left arrow ]key pressed>
<set{ key press valid? }to( 1
<wait until> <not> <key[ left arrow ]pressed?> >>
<repeat until> <( <{ key press valid? }> <=> 0 )>
<if> <key[ left arrow ]pressed?>
<wait until>   <not> <key[ left arrow ]pressed?> >>
.....[Bash script]
<wait until>   <not> <key[ left arrow ]pressed?> >>
<stop script>
<end>
<end>

<when[ left arrow ]key pressed>
<wait( 1 )secsc>
<set{ key press valid? }to( 0[/blocks]


Scratch on!

wow! thx so much! it works very well! im so stupid! i never tought of using variables... lol! thx so much for the script! ill make it work well. then i'll upload a new version with bashing and stuff^^

Offline

 

#10 2009-05-29 18:13:42

pepepaco1980
Scratcher
Registered: 2009-05-23
Posts: 9

Re: button pressed repeatedly

measure the time between keys, if the time between the two presed keys if short enough and are the same keys then do something.

a timer that records the last value when key when was last presed, reset every 1 secod, ( to wait for the first key again, then compare with the last hit. afther that comapre the time, and key value.

Offline

 

#11 2009-05-30 04:20:07

MyRedNeptune
Community Moderator
Registered: 2007-05-07
Posts: 1000+

Re: button pressed repeatedly

Dudeson wrote:

wow! thx so much! it works very well! im so stupid! i never tought of using variables... lol! thx so much for the script! ill make it work well. then i'll upload a new version with bashing and stuff^^

You are very welcome.  smile


http://i52.tinypic.com/5es7t0.png I know what you're thinking! "Neptune! Get rid of those filthy advertisements and give us back the Zarathustra siggy, you horrible person!" Well, don't worry about it, the Zara siggy will be back soon, new and improved! ^^ Meanwhile, just do what the sig tells you to. >.>

Offline

 

Board footer