Discuss Scratch

purpleguystoast
Scratcher
16 posts

When Sprite Clicked

Hi- for my game, when a sprite (that isn't the player) is clicked, i want the player to say something. I was thinking of trying this:
when this sprite clicked
broadcast [clicked]

And then for the player sprite:
when I receive [clicked]
say [---] for (2) secs

Can anyone tell me if there's any script better than this one?
bRuHbRuHmEmEmAn
Scratcher
500+ posts

When Sprite Clicked

Yeah, that works. If you want to use fewer blocks, that's the perfect method. If not, then here you go.

when green flag clicked
forever
if <<touching [mouse-pointer v] ?> and <mouse down?>> then
set [SpriteWasClicked v] to [yes]
end
end

And in the player sprite:

when green flag clicked
forever
if <(SpriteWasClicked) = [yes]> then
say [Hello!] for (2) secs
end
end
ayyyyes10135
Scratcher
100+ posts

When Sprite Clicked

forever
if <<touching [ mouse pointer] ?> and <mouse down?>> then
broadcast [ clicked]
wait until <not <mouse down?>>

end
end

this broadcasts too. the wait untill not mouse down makes it so that it wont spam
cwknikhil15842
Scratcher
100+ posts

When Sprite Clicked

Try this:

ayyyyes10135
Scratcher
100+ posts

When Sprite Clicked

cwknikhil15842 wrote:

Try this:



that wouldnt work because you have to do the code first otherwise the wait untill block will only make it so that the code will do it after you release the mouse
purpleguystoast
Scratcher
16 posts

When Sprite Clicked

Hi! I just released my game. https://scratch.mit.edu/projects/500005387
The sprite I needed to be clicked on was the kid on the first level when you start the game. (I am adding more)
cwknikhil15842
Scratcher
100+ posts

When Sprite Clicked

ayyyyes10135 wrote:

cwknikhil15842 wrote:

Try this:



that wouldnt work because you have to do the code first otherwise the wait untill block will only make it so that the code will do it after you release the mouse
Isn't that how a when sprite clicked works?
Idkdidntask
Scratcher
7 posts

When Sprite Clicked

well i think try this:

when green flag clicked
go to front

[scratchblocks]
when this sprite clicked
repeat (2)
create clone of [myself v]
go to [random position v]
play sound [chord v]
end
[/scratchblocks]

assignisions:


[scratchblocks]
when green flag clicked
imagine
program
add (letter (s) of [and share]) to [list v]
[/scratchblocks]

[scratchblocks]
(O) _ (O)
[/scratchblocks]

[scratchblocks]
when green flag clicked
forever
forever
forever
forever
forever
forever
forever
forever
forever
forever
set [my variable v] to [1]
end
[/scratchblocks]

Last edited by Idkdidntask (Jan. 13, 2023 12:57:50)

Idkdidntask
Scratcher
7 posts

When Sprite Clicked

Greypath wrote:

A salt seller used to carry the salt bag on his donkey to the market every day.

On the way they had to cross a stream. One day the donkey suddenly tumbled down the stream and the salt bag also fell into the water. The salt dissolved in the water and hence the bag became very light to carry. The donkey was happy.

Then the donkey started to play the same trick every day.

The salt seller came to understand the trick and decided to teach a lesson to it. The next day he loaded a cotton bag on the donkey.

Again it played the same trick hoping that the cotton bag would be still become lighter.

But the dampened cotton became very heavy to carry and the donkey suffered. It learnt a lesson. It didn’t play the trick anymore after that day, and the seller was happy.

what
deck26
Scratcher
1000+ posts

When Sprite Clicked

Greypath wrote:

A salt seller used to carry the salt bag on his donkey to the market every day.

On the way they had to cross a stream. One day the donkey suddenly tumbled down the stream and the salt bag also fell into the water. The salt dissolved in the water and hence the bag became very light to carry. The donkey was happy.

Then the donkey started to play the same trick every day.

The salt seller came to understand the trick and decided to teach a lesson to it. The next day he loaded a cotton bag on the donkey.

Again it played the same trick hoping that the cotton bag would be still become lighter.

But the dampened cotton became very heavy to carry and the donkey suffered. It learnt a lesson. It didn’t play the trick anymore after that day, and the seller was happy.
Please don't spam. This has nothing to do with the topic.

Powered by DjangoBB