Being somewhat new to Scratch, my attempts at a script, which may be a bit beyond my capacity thus far, have so far been only semi-successful.
I would like to have the ability to mouse click a sprite to activate it, then do the same to deactivate it.
Essentially, I'd like to have multiple sprites on the screen which the user can click at any given time and have them deactivate each one at any given time as well.
Unfortunately, what I have so far works only somewhat; when clicked, the specific sprite is activated and when clicked again, it's deactivated, but I would like to have the ability for the user to click on and off repeatedly as necessary.
Here's a link if you'd like to see what my script looks like so far:
http://www.watermans.org/scratch.jpg
Offline
Replace this section:
forever if <not <mouse down>> set tempo to (133) bpm switch to costume [costume2 v] play note (96 v) for (0.5) beats if <<touching [mouse-pointer v]> and <mouse down>> switch to costume [costume1 v] stop script endwith:
forever if <not <mouse down>> set tempo to (133) bpm if <<touching [mouse-pointer v]> and <mouse down>> switch to costume [costume1 v] else switch to costume [costume2 v] play note (96 v) for (0.5) beats endand it will work.
Offline
I think employing some variables and broadcasting can help quite a bit:
@rdococ: I don't think that will fully remedy the situation as the sprite will resume activation upon releasing the mouse, even though it is supposed to deactivate on click.
Last edited by Kileymeister_test (2013-01-04 15:16:19)
Offline
Kileymeister_test, this is great! I haven't had a chance to experiment yet with broadcasting, but your scripts really give me a better understanding of it for sure.
This works wonderfully so far in my script. Is there any way to hide the variable, or do you simply place your sprite in front of it?
Thanks so much, everyone!
Offline
Actually, it appears I overlooked the "hide variable..." function, so that seems to have worked.
Also, now that I have input 2 different sprites with two different sounds, they seem to activate simultaneously with the above script, regardless of my clicking one or the other. Any thoughts?
Offline
Okay it looks like I've figured out how to keep them separately activated by changing the name of the broadcast for each.
NOW, though, it seems after the first sprite is activated, I have to double click all subsequent sprites to activate them. Not a terrible problem as this is light years from where I was. Just updating on my progress as it happens.
Offline
Instead of changing the name of the broadcast, you can do something else which I should have told you in the first post (sorry!).
Variables can be public (meaning they apply to all sprites) or private (meaning they apply to a single sprite). To make a private variable, check the "For this sprite only" box when creating it and writing its name.
You can tell a variable is private if it is separated from other variables by a line like this:
If you give each sprite a private variable, and use that private variable in its scripts, they should all react independently from each other even though they are all using the same broadcast name.
Last edited by Kileymeister_test (2013-01-04 17:06:50)
Offline