Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » A way to check if a certain sprite has been clicked
- hiddenblitz
-
New Scratcher
7 posts
A way to check if a certain sprite has been clicked
Hi guys, I'm trying to find a way for another sprite to react if and only if a certain sprite has been clicked previously. Im trying to make a number sequence game and Ive gotten most of the steps down except I dont know how to make the game check for if the person clicked the wrong sprite and if so, fail them. Currently they are able to click the last number and complete the round so im trying to find a way to make sure that the previous sprites have been clicked before clicking on the last sprite in order to move the the next round.
- -Nikimaster-
-
Scratcher
73 posts
A way to check if a certain sprite has been clicked
Quick question, are the things you click different clones or different sprites? This is somewhat important
- -Nikimaster-
-
Scratcher
73 posts
A way to check if a certain sprite has been clicked
I am not too sure how your game works so can you just tell me? Is it the ball you click or the numbers
- unsullied123-rblx
-
Scratcher
100+ posts
A way to check if a certain sprite has been clicked
if it's just a sprite
if it's a clone
when this sprite clicked
set [sprite clicked? v] to [1]
when I receive [check if that sprite was clicked v]
if <(sprite clicked?) = [1]> then
... // do whatever you want to happen if the sprite was clicked
else
... // do whatever you want to happen if the sprite wasn't clicked
end
if it's a clone
when I start as a clone
forever
if <<mouse down?> and <touching [mouse pointer v] ?>> then
set [sprite clicked? v] to [1]
end
end
when I receive [check if that sprite was clicked v]
if <(sprite clicked?) = [1]> then
... // do whatever you want to happen if the sprite was clicked
else
... // do whatever you want to happen if the sprite wasn't clicked
end
- MistaLOD
-
Scratcher
100+ posts
A way to check if a certain sprite has been clicked
Make a new variable called “Is clicked?” and make sure it's “For this sprite only”
Then add this:
This is pretty much the simplest way to do this. If you want other sprites to know if it's clicked, then use the reporter block under the (light blue) Sensing category.
Hope this helps!
Then add this:
when this sprite clicked
set [Is clicked? v] to (1) // you can also use "yes"
when green flag clicked
set [Is clicked? v] to (0) // you can also use "no"
This is pretty much the simplest way to do this. If you want other sprites to know if it's clicked, then use the reporter block under the (light blue) Sensing category.
<([Is clicked? v] of [Button v]) = (1)>
Hope this helps!
Last edited by MistaLOD (March 7, 2023 20:52:03)
- hiddenblitz
-
New Scratcher
7 posts
A way to check if a certain sprite has been clicked
I am not too sure how your game works so can you just tell me? Is it the ball you click or the numbersThe numbers turn to the balls after 1.5 seconds of waiting and the goal is to click the numbers in the correct sequence with memorization.
- 10data10
-
Scratcher
100+ posts
A way to check if a certain sprite has been clicked
I think what you want is a global variable that has the number of the ball you are expecting to be clicked. Your “1” sprite would have
Then your ShowSprite custom block could reset Expected Number back to 1 for the next test.
The other sprites (2,3,4) would have the same script but test for their number.
when this sprite clicked
if <[Expected Number] = [1]> then
change [Expected Number v] by (1)
else
broadcast [Game Over v]
end
Then your ShowSprite custom block could reset Expected Number back to 1 for the next test.
The other sprites (2,3,4) would have the same script but test for their number.
- Discussion Forums
- » Help with Scripts
-
» A way to check if a certain sprite has been clicked