Hello,
I am working on my first Scratch project (a simple game) but I cannot find a way to accommodate multiple key presses. For example: I would like the '->' key to make Sprite1 move 10 steps to the right, and the 'd' key to make Sprite2 move 10 steps to the right, but pressing '->' and 'd' at the same time will cause Sprite3 to move 10 steps to the right. Is this kind of behavior even possible in Scratch?
Any help whatsoever would be greatly appreciated - thanks so much!
Offline
Well... Try making two variables, I'll call them varA and varB for this.
On the first sprite, add this:
if <key [ right arrow ] pressed> {
set varA to 1
}
else {
set varA to 0
}
if <key [ d ] pressed> {
set varB to 1
}
else {
set varB to 0
}
if <varA = 1> and <varB = 0> {
move 10 steps
}
And then on the second sprite:
if <varA = 0> and varB = 1> {
move 10 steps
}
And then on the third
if <varA = 1> and <varB = 1> {
move 10 steps
}
Offline
I tried your solution but my second variable (varB in your example) only stays at 1 for a fraction of a second, and then returns to 0 immediately no matter what I do. How do I make a variable stay at 1 indefinitely?
Thanks again for your help.
Offline
CharlieAZ wrote:
so did you fix the button changing thingy?
"Button changing thingy?" Do you mean pressing two keys at once to get Sprite3 to move? Then yes I did. I used variables like juststickman suggested and added a wait statement immediately after "Set var___ to 1" so there would be a little bit of lag time after each key press to make "catching" them easier.
Offline