Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » 'Not touching edge' not working
- alexis-x
-
Scratcher
3 posts
'Not touching edge' not working
Hi all,
This is my first ever project and the first bit of programming I've done since dabbling with BBC Basic as a child. So, please be gentle with me!
I'm working on a game called Sky Cats, which you can have a look at here.
In a nutshell, cats jump out of windows and you stop them from hitting the ground by clicking on them to give them a balloon. Your score should go up by one for each cat you save, and go down by one for each cat that hits the ground.
The trouble is, the score is going up when the cats are clicked on after hitting the ground. The bit of code I have which I think should stop this happening is as follows:
It's sensing that the sprite is touching the edge in another part of the code and reducing the ‘clicked’ value by 1, then playing a bell sound, so I don't understand why the ‘not touching edge’ variable isn't preventing the ‘clicked’ value going up by 1.
Any tips or advice greatly received. Also, if anyone is up for looking at the project and suggesting ways of improving the rest of the code too, that would be lovely!
Many thanks,
Alexis
This is my first ever project and the first bit of programming I've done since dabbling with BBC Basic as a child. So, please be gentle with me!
I'm working on a game called Sky Cats, which you can have a look at here.
In a nutshell, cats jump out of windows and you stop them from hitting the ground by clicking on them to give them a balloon. Your score should go up by one for each cat you save, and go down by one for each cat that hits the ground.
The trouble is, the score is going up when the cats are clicked on after hitting the ground. The bit of code I have which I think should stop this happening is as follows:
forever
if <not <touching [ edge ] ?>> then
wait until <[y position] < [16]>
wait until <not <mouse down?>>
wait until <mouse down?>
if <touching [ mouse-pointer ] ?> then
change [clicked] by (1)
end
end
end
It's sensing that the sprite is touching the edge in another part of the code and reducing the ‘clicked’ value by 1, then playing a bell sound, so I don't understand why the ‘not touching edge’ variable isn't preventing the ‘clicked’ value going up by 1.
Any tips or advice greatly received. Also, if anyone is up for looking at the project and suggesting ways of improving the rest of the code too, that would be lovely!
Many thanks,
Alexis
Last edited by alexis-x (July 28, 2017 15:49:59)
- PhysicsWhizz
-
Scratcher
100+ posts
'Not touching edge' not working
Hello, and welcome to Scratch!
The bit of code you have to prevent the score from increasing when the cats are clicked after touching the ground is incredibly confusing. I wouldn't recommend using “wait until” blocks too much.
Anyways, I think that the reason why it isn't working is because it's only checking if the cat isn't touching the ground once. After the first “if” block checking if the cat isn't touching the edge, there aren't any further checks to make sure that the cat is in the air when the player clicks on it. You have the entire “if” block in a forever loop to prevent this, but since you have wait until blocks in your code, the loop basically pauses.
To fix this, you should use only a couple if blocks instead of using wait until blocks.
For example:
If you have any questions, feel free to ask.
Scratch on!
The bit of code you have to prevent the score from increasing when the cats are clicked after touching the ground is incredibly confusing. I wouldn't recommend using “wait until” blocks too much.
Anyways, I think that the reason why it isn't working is because it's only checking if the cat isn't touching the ground once. After the first “if” block checking if the cat isn't touching the edge, there aren't any further checks to make sure that the cat is in the air when the player clicks on it. You have the entire “if” block in a forever loop to prevent this, but since you have wait until blocks in your code, the loop basically pauses.
To fix this, you should use only a couple if blocks instead of using wait until blocks.
For example:
forever
if <<<(y position) > [-150]> and <(y position) < [16]>> and <<touching [mouse-pointer v] ?> and <mouse down?>>> then
set [clicked v] to [1]
end
end
If you have any questions, feel free to ask.

Scratch on!
Last edited by PhysicsWhizz (July 28, 2017 17:16:00)
- alexis-x
-
Scratcher
3 posts
'Not touching edge' not working
That's brilliant - thanks very much for your help. The reason I used the wait until blocks was that I read on the scratch wiki that this was a workaround for a ‘when this sprite clicked’ control block… or at least that was my understanding.
So adjusting the code as you've suggested has pretty much worked, but the downside is that you no longer have to actually click on the cat to save it, you can just click anywhere and drag the mouse to the cat. This is fine, and if it can't be improved upon I'll take it, but is there any way of insisting that the user clicks on the sprite to rescue it with or without using wait until blocks?
Cheers,
Alexis
So adjusting the code as you've suggested has pretty much worked, but the downside is that you no longer have to actually click on the cat to save it, you can just click anywhere and drag the mouse to the cat. This is fine, and if it can't be improved upon I'll take it, but is there any way of insisting that the user clicks on the sprite to rescue it with or without using wait until blocks?
Cheers,
Alexis
- gtoal
-
Scratcher
1000+ posts
'Not touching edge' not working
cool, but the premise of the game is flawed - cats *always* land on their feet and walk away regardless of from how high you drop them :-) (I assume they're so light and fluffy that wind resistance causes a lower terminal velocity than say a human dropped from the same height, and that that velocity is always below what would be terminal to a cat…)
- PhysicsWhizz
-
Scratcher
100+ posts
'Not touching edge' not working
cool, but the premise of the game is flawed - cats *always* land on their feet and walk away regardless of from how high you drop them :-) (I assume they're so light and fluffy that wind resistance causes a lower terminal velocity than say a human dropped from the same height, and that that velocity is always below what would be terminal to a cat…)
Spot on!
- TheUltimatum
-
Scratcher
1000+ posts
'Not touching edge' not working
cool, but the premise of the game is flawed - cats *always* land on their feet and walk away regardless of from how high you drop them :-) (I assume they're so light and fluffy that wind resistance causes a lower terminal velocity than say a human dropped from the same height, and that that velocity is always below what would be terminal to a cat…)gtoal as always having a little bit too much fun with his forum posts.
- alexis-x
-
Scratcher
3 posts
'Not touching edge' not working
cats *always* land on their feet and walk away regardless of from how high you drop them :-)
Well, it's true that they always land on their feet, but they don't always walk away. Besides, you're making the (frankly ridiculous) assumption that the floor (which is just out of shot) isn't covered in spikes!

Anyway, any tips on how to force the user to click directly on the cats to save them rather than being able to click anywhere and drag over the sprite?
- Discussion Forums
- » Help with Scripts
-
» 'Not touching edge' not working