Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Pressing a button to create a new action
- NJMarlborough
-
New Scratcher
6 posts
Pressing a button to create a new action
Hi
I am making a game with my 8 year old son who desperately wants to have an active electricity button in his flying cat game. The idea is after the flying cat catches 10 lightening bolts the electricity button becomes active and generates electricity shocks following the flying cat. Is there a way to code
When score = x
Button becomes active (button changes colour or glows)
Then, when button is pressed by mouse
Cat has electricity glow and flies faster
Any help or tips would be much appreciated. I don't seem to be able to find the right connection of boxes and commands to get this into the code
All the best
I am making a game with my 8 year old son who desperately wants to have an active electricity button in his flying cat game. The idea is after the flying cat catches 10 lightening bolts the electricity button becomes active and generates electricity shocks following the flying cat. Is there a way to code
When score = x
Button becomes active (button changes colour or glows)
Then, when button is pressed by mouse
Cat has electricity glow and flies faster
Any help or tips would be much appreciated. I don't seem to be able to find the right connection of boxes and commands to get this into the code
All the best
- Yusei-Fudo
-
Scratcher
1000+ posts
Pressing a button to create a new action

It would be best to see the project. Would you mind sharing it with us?
- NJMarlborough
-
New Scratcher
6 posts
Pressing a button to create a new action
Thanks very much for the quick reply, the project is shared (link below). Any tips would be much appreciated.
All the best
https://scratch.mit.edu/projects/544362414/
All the best
https://scratch.mit.edu/projects/544362414/
- mstone326
-
Scratcher
1000+ posts
Pressing a button to create a new action
Love your son's idea! When he flies faster when the electricity starts, are we looking at moving the cat up and down faster?
Is it every 10 points for lightning for a certain amount of time? We can help him make the cat electric! great idea (I teach technology k-8)
Is it every 10 points for lightning for a certain amount of time? We can help him make the cat electric! great idea (I teach technology k-8)
- MasterofTheBrick
-
Scratcher
1000+ posts
Pressing a button to create a new action
Welcome to Scratch!
The code in the button sprite should be as follows:
Now to change the speed, we will have to tweak the code in the clouds sprite a little bit:
And finally, add this in the cat sprite:
The code in the button sprite should be as follows:
when green flag clicked
set [ghost v] effect to (100) //this will hide the button
wait until <(score) = [5]> //the orange block can be found in the variables section of the project editor
repeat (10)
change [ghost v] effect by (-10) //initiates a quick fade-in
end
wait until <<mouse down?> and <touching [mouse-pointer v] ?>> //senses that the button was pressed
broadcast [effects v] //this will enable the change of speed and the glowing effect
Now to change the speed, we will have to tweak the code in the clouds sprite a little bit:
when green flag clicked
set [speed v] to [5] //add this in
forever
change x by (500)
next costume
repeat (100)
change x by ((-1) * (speed)) //add this in
end
end
when I receive [effects v] //add this in the clouds sprite too
set [speed v] to [10]
And finally, add this in the cat sprite:
when I receive [effects v]
forever
repeat (8)
change [brightness v] effect by (5)
end
repeat (8)
change [brightness v] effect by (-5)
end
end
Last edited by MasterofTheBrick (June 25, 2021 01:53:41)
- Geometry_Dash3
-
Scratcher
100+ posts
Pressing a button to create a new action
Last edited by Geometry_Dash3 (Oct. 16, 2021 17:03:52)
- MasterofTheBrick
-
Scratcher
1000+ posts
Pressing a button to create a new action
when green flag clicked
if <[score] = [number]> then
switch costume to [your costume v]
when this sprite clicked
if <(costume #) = [activated]> then
broadcast [your message v]
end
when I receive [message v]
switch costume to [ glowing cat v]
I don't think this helps much, have you looked inside the project? After doing so you might want to change your code to better suit the game.
Last edited by MasterofTheBrick (June 25, 2021 01:42:49)
- Geometry_Dash3
-
Scratcher
100+ posts
Pressing a button to create a new action
Last edited by Geometry_Dash3 (Oct. 16, 2021 17:03:31)
- Yusei-Fudo
-
Scratcher
1000+ posts
Pressing a button to create a new action
Thanks very much for the quick reply, the project is shared (link below). Any tips would be much appreciated.
All the best
https://scratch.mit.edu/projects/544362414/
Ok, so do you want the button to be active once every 10 points?
How do you want it to work.
I also have a suggestion on how to improve movements:

The variable acceleration determines how fast the cat is moving. Also, with this, you can increase the cat's movements to a more appealing way. Trust me.
- mstone326
-
Scratcher
1000+ posts
Pressing a button to create a new action
Thanks very much for the quick reply, the project is shared (link below). Any tips would be much appreciated.
All the best
https://scratch.mit.edu/projects/544362414/
Ok, so do you want the button to be active once every 10 points?
How do you want it to work.
I also have a suggestion on how to improve movements:
The variable acceleration determines how fast the cat is moving. Also, with this, you can increase the cat's movements to a more appealing way. Trust me.
Don't forget, the Scratcher is 8. Let's wait for dad to respond and keep this accessible. I teach this age, we are not going to be able to use acceleration and absolute value.
We can help with code in a way that an 8 year old can do it. While everyone's feedback is appreciated, let's work together to keep this solution simple.
- Thingied
-
Scratcher
1000+ posts
Pressing a button to create a new action
I agree. When I was around 8 the ()of() block and variables made no sense so I would suggest trying to make scripts that are as simple and efficient as possible.Thanks very much for the quick reply, the project is shared (link below). Any tips would be much appreciated.
All the best
https://scratch.mit.edu/projects/544362414/
Ok, so do you want the button to be active once every 10 points?
How do you want it to work.
I also have a suggestion on how to improve movements:
-snip-
The variable acceleration determines how fast the cat is moving. Also, with this, you can increase the cat's movements to a more appealing way. Trust me.
Don't forget, the Scratcher is 8. Let's wait for dad to respond and keep this accessible. I teach this age, we are not going to be able to use acceleration and absolute value.
We can help with code in a way that an 8 year old can do it. While everyone's feedback is appreciated, let's work together to keep this solution simple.
Simplified version:
when green flag clicked
forever
if <key [up arrow v]pressed?> then // checks if the up arrow key is being pressed
change y by (up speed::grey)//the gray blocks are placeholders
end
if <key [down arrow v] pressed?> then // check if the down arrow is being pressed.
change y by (down speed::grey)
- NJMarlborough
-
New Scratcher
6 posts
Pressing a button to create a new action
Thank you so much for all your comments. He is coming over tomorrow afternoon so I can ask him if he wants this to be a repeated event every 10 points or so (I expect he will) and about the speed of the cat (I think he will want it to move faster as well along with the glow).
Thanks so much again for all the comments and pointers I am going to have a look at them tomorrow morning before he comes over. Hopefully I will be able to explain them to him.


All the best
- mstone326
-
Scratcher
1000+ posts
Pressing a button to create a new action
Feel free to post again, as you see there are plenty here always willing to help. With all of us combined we will get that cat ELECTRIC!
- Yusei-Fudo
-
Scratcher
1000+ posts
Pressing a button to create a new action
Thank you so much for all your comments. He is coming over tomorrow afternoon so I can ask him if he wants this to be a repeated event every 10 points or so (I expect he will) and about the speed of the cat (I think he will want it to move faster as well along with the glow).
Thanks so much again for all the comments and pointers I am going to have a look at them tomorrow morning before he comes over. Hopefully I will be able to explain them to him.
All the best
Always good to help!- snip -
- snip -
Removed the big thumbs, because people might start to think it's annoying.
Last edited by Yusei-Fudo (Aug. 4, 2021 03:57:02)
- NJMarlborough
-
New Scratcher
6 posts
Pressing a button to create a new action
Hi,
Sorry I am coming back to this one after a little while. I think I made a bit of a mess of the coding and I couldn't quite understand in which part the update bit of coding needs to go (is it in the clouds icon?)
So there were a couple of things that changed in the spec from last time. He doesn't want the cat to glow now when the button is pressed (I think I fixed that bit okay) which is a bit of a pity as I thought it was a really cool idea, but for whatever reason that's not a goer now.
The 2 bits that I am struggling with are
1) the button seems to be active now the whole time for some reason, can anyone suggest what I did wrong in the code
2) the second thing is the clouds don't immediately revert back to the right hand side of the screen when they speed up, I couldn't figure out how to fix this
Any help or suggestions would be much appreciated
All the best
- Yusei-Fudo
-
Scratcher
1000+ posts
Pressing a button to create a new action
Alright then, LET'S DEBUG!


Edit: I'll put my questions here instead of multiple posts.
1. Do you want the button to fade out and hide when it's clicked because that's not put into your program:

My answers goes here:
Problem:
For the cloud part, the reason it's not going back the moment it reaches the edge is because of this (the repeat loop isn't finished running by the time the cloud reaches the edge, so it doesn't run the block that returns it to the right side of the screen):

Solution
Your loop doesn't finishes before the cloud reaches the edge of the screen. For that, why don't you just change that entire forever loop to this:




Edit: I'll put my questions here instead of multiple posts.
1. Do you want the button to fade out and hide when it's clicked because that's not put into your program:

My answers goes here:
Problem:
For the cloud part, the reason it's not going back the moment it reaches the edge is because of this (the repeat loop isn't finished running by the time the cloud reaches the edge, so it doesn't run the block that returns it to the right side of the screen):

Solution
Your loop doesn't finishes before the cloud reaches the edge of the screen. For that, why don't you just change that entire forever loop to this:

Last edited by Yusei-Fudo (Aug. 4, 2021 02:12:38)
- Yusei-Fudo
-
Scratcher
1000+ posts
Pressing a button to create a new action
In fact, you can do the same thing with the lightning bolt to make it less buggy:

For your cat, you can make smoother movements like this:

Create this new Script in the Lightning bolt sprite:

And back in the cat flying sprite, create this script:

These suggestions really improves your project's functionality quality by a lot. Hope they help.

For your cat, you can make smoother movements like this:

Create this new Script in the Lightning bolt sprite:

And back in the cat flying sprite, create this script:

These suggestions really improves your project's functionality quality by a lot. Hope they help.
- NJMarlborough
-
New Scratcher
6 posts
Pressing a button to create a new action
Thank you so much, I'll take a look at these tomorrow morning before he comes over in the afternoon.
Separately, do you know if there are any materials available that teach how to code in this language? I am a bit of a novice myself and I cannot really teach my son unless I come up to speed a bit etc….
All the best
- Thingied
-
Scratcher
1000+ posts
Pressing a button to create a new action
Separately, do you know if there are any materials available that teach how to code in this language? I am a bit of a novice myself and I cannot really teach my son unless I come up to speed a bit etc….https://en.scratch-wiki.info/ . Search up whatever about scratch and you'll probably get an answer.
- Yusei-Fudo
-
Scratcher
1000+ posts
Pressing a button to create a new action
Thank you so much, I'll take a look at these tomorrow morning before he comes over in the afternoon.
Separately, do you know if there are any materials available that teach how to code in this language? I am a bit of a novice myself and I cannot really teach my son unless I come up to speed a bit etc….
All the best
Of course! You can use the Scratch tutorials given by Scratch, and this forum is also a great place for learning too. This is a friendly place (well, sometimes people make dum mistakes, no trying to be offensive).
Other than that, I don't know much resources, YouTube Scratch tutorials? I learned Scratch by myself and other fellow Scratchers that helps me on the forum, nobody really taught me much outside of this forum because by the time my CS teachers taught this language to the class, I was already well ahead of everyone else… So yeah. IDK much resources. Maybe other people do.
- Discussion Forums
- » Help with Scripts
-
» Pressing a button to create a new action






