Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Creating an if with two buttons pressed?
- arkoyda
-
New Scratcher
4 posts
Creating an if with two buttons pressed?
Hello, can we in someway create an if command that checks if two objects are pressed one after the other?
I want to check if a button pressed then if another pressed do {…. } things.
Is this possible?
Cause if an object pressed i cant find a way to add another object in that if.
Thanks in advance.
I want to check if a button pressed then if another pressed do {…. } things.
Is this possible?
Cause if an object pressed i cant find a way to add another object in that if.
Thanks in advance.
when [ v] key pressed
when [ v] key pressed
set [ v] to []
Last edited by arkoyda (March 25, 2018 22:30:19)
- Tookiekat_studios
-
Scratcher
38 posts
Creating an if with two buttons pressed?
I think so. if this does not work, i tried.
when [ v] key pressed
if <key [ v] pressed?> then
set [ v] to [jk]
end
- arkoyda
-
New Scratcher
4 posts
Creating an if with two buttons pressed?
when this sprite clicked
i mean when an object is clicked… not a key from keyboard. my mistake.
can we do this with objects?
an object in another object clicked.
Last edited by arkoyda (March 25, 2018 22:38:33)
- asivi
-
Scratcher
1000+ posts
Creating an if with two buttons pressed?
when this sprite clicked
i mean when an object is clicked… not a key from keyboard. my mistake.
can we do this with objects?
an object in another object clicked.
Perhaps to avoid more mistakes you want to explain that you expect to achieve more in detail.
Let say you have button1 and button2, what of those sprites must be clicked first?
What must happen if someone click the wrong button firstly?
- arkoyda
-
New Scratcher
4 posts
Creating an if with two buttons pressed?
i want to make a puzzle game with 4 categories.
Lets say we have 4 categories on top (4 objects) and 16 objects on bottom of them. So a player must choose the right category for every object.
So i need to check if he clicks first category for example, then if he clicks an object that fits in that category i will give him +1 on his score.
Lets say we have 4 categories on top (4 objects) and 16 objects on bottom of them. So a player must choose the right category for every object.
So i need to check if he clicks first category for example, then if he clicks an object that fits in that category i will give him +1 on his score.
- asivi
-
Scratcher
1000+ posts
Creating an if with two buttons pressed?
You could create a variable (category) that you set to nothing at the start, then when you click one of your 4 buttons if (category)=nothing you set the variable to its number(1 to 4) or a specific name, and you could do so that when clicked the others they check iif such variable is set to the category number(or name) if it is belonging to (category)=the appropiate number it increases score and set (category) to nothing, in case it doesn't belong to the specified category just set (category) to nothing.
Your sounds like being good for cloning stuff.
Your sounds like being good for cloning stuff.
Last edited by asivi (March 25, 2018 23:33:46)
- asivi
-
Scratcher
1000+ posts
Creating an if with two buttons pressed?
I mean
when green flag clicked
set [category v] to [_]
set [score v] to [0]
when this sprite clicked
if <(category) = [_]> then
set [category v] to [3]
end
when this sprite clicked
if <(category) = [3]> then
change [score v] by (1)
end
set [category v] to [_]
- Programaster20
-
Scratcher
99 posts
Creating an if with two buttons pressed?
when green flag clicked
forever
if <<key [ v] pressed?> and <key [ v] pressed?>> then
do whatever you need the sprite to do
end
end
it works, i use it a lot.
Last edited by Programaster20 (March 25, 2018 23:46:45)
- Programaster20
-
Scratcher
99 posts
Creating an if with two buttons pressed?
but im not sure if
works
when [key ... and key ... pressed v] key pressed
works
- asivi
-
Scratcher
1000+ posts
Creating an if with two buttons pressed?
but im not sure ifwhen [key ... and key ... pressed v] key pressed
works
Please guy, do not spam with scratchblocks. Thanks.
- asivi
-
Scratcher
1000+ posts
Creating an if with two buttons pressed?
I meanwhen green flag clicked
set [category v] to [_]
set [score v] to [0]
when this sprite clicked
if <(category) = [_]> then
set [category v] to [3]
end
when this sprite clicked
if <(category) = [3]> then
change [score v] by (1)
end
set [category v] to [_]
when this sprite clicked
if <(category) = [3]> then
change [score v] by (1)
hide//perhaps hide and stamp to prevent being clicked again?
stamp
else
set [category v] to [_]//maybe you don´t want to reset the category until the player fails
end
Last edited by asivi (March 26, 2018 08:47:56)
- press_start019249
-
Scratcher
6 posts
Creating an if with two buttons pressed?
when green flag clicked
if <<key [ v] pressed?> and <key [ v] pressed?>> then
end
Last edited by press_start019249 (March 20, 2021 04:51:20)
- 0p0p0p0p0p0p0pp
-
Scratcher
1 post
Creating an if with two buttons pressed?
@press_start019249 the if then block needs to be in a forever loop otherwise it will only run when the green flag is clicked and no other time.
Kind regards, @0p0p0p0p0p0p0pp
Kind regards, @0p0p0p0p0p0p0pp
- Discussion Forums
- » Help with Scripts
-
» Creating an if with two buttons pressed?





