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
[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!
Offline
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
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
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
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.
Offline
Actually, this belongs in All About Scratch... Troubleshooting is for bugs/glitches, while All About Scratch is for asking questions.
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!
Offline
MyRedNeptune wrote:
Actually, this belongs in All About Scratch... Troubleshooting is for bugs/glitches, while All About Scratch is for asking questions.
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
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
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.
Offline