Discuss Scratch

gubzgubz
New Scratcher
9 posts

Manage collision between 2 sprites

Hi All,

I am new to scratch and I am doing my 1st project.
It is a duel between 3 protagonist (the good, the bad and the ugly).
When one of them is touched by a bullet, the game must stop.
But, in the real world (my program!), the bullets just continue to fly and nothing happen.
Here is the script I currently use :
whenspacekeypressedwait1secsiftouching bad?bullet1orbullet2orbullet3thengotox:0y:0switchcostumetodeathstopall

I you want to help me, you could check the project here :
https://scratch.mit.edu/projects/480713176

Thank you for your suggestions.
Best
deck26
Scratcher
1000+ posts

Manage collision between 2 sprites

Where do you have that script? What I see is the following which is not the same

whenclickedifkeyspacepressed?thenyourcodehere
gubzgubz
New Scratcher
9 posts

Manage collision between 2 sprites

Thx Deck26

I put my script on the sprite called “Bon”
My Idea is to duplicate this kind of script for each person

deck26
Scratcher
1000+ posts

Manage collision between 2 sprites

You still don't have the script you originally showed, you have what I showed. Do you think otherwise?
gubzgubz
New Scratcher
9 posts

Manage collision between 2 sprites

I have several scripts on the same page.
The one I showed is below the others
deck26
Scratcher
1000+ posts

Manage collision between 2 sprites

gubzgubz wrote:

I have several scripts on the same page.
The one I showed is below the others
I still disagree and I've run the clean up blocks option to ensure I'm not missing anything.

You do not have a script with the ‘when space key pressed’ hat block in the project you've provided the link to. Ifg you're seeing it you either need to save the project again or check that you haven't made a copy.

Do you understand that these scripts are very different things?

whenclickedifkeyspacepressed?thencodeblockwhenspacekeypressedcodeblock

Last edited by deck26 (Feb. 1, 2021 10:06:23)

dertermenter
Scratcher
1000+ posts

Manage collision between 2 sprites

on the original code in the Op, I think you need to put a forever loop around the If block
wasdcoceoe
Scratcher
100+ posts

Manage collision between 2 sprites

You put the if space pressed block outside, which causes the project to check if space is pressed on the first frame, and if it is not pressed the code stops running altogether.
gubzgubz
New Scratcher
9 posts

Manage collision between 2 sprites

deck26 wrote:

gubzgubz wrote:

I have several scripts on the same page.
The one I showed is below the others
I still disagree and I've run the clean up blocks option to ensure I'm not missing anything.

You do not have a script with the ‘when space key pressed’ hat block in the project you've provided the link to. Ifg you're seeing it you either need to save the project again or check that you haven't made a copy.

Do you understand that these scripts are very different things?

whenclickedifkeyspacepressed?thencodeblockwhenspacekeypressedcodeblock

You're my man !
24h to try several scripts for that and it was so simple!
I use the
whenclickedInsteadofwhenspacekeypressedThankyousomuchforyourcontributionwhenclicked

Last edited by gubzgubz (Feb. 1, 2021 12:12:41)

deck26
Scratcher
1000+ posts

Manage collision between 2 sprites

So what you had was a script that checked for space as soon as the project started (green flag clicked) but not after that so that script virtually always finished running a split second after you clicked the green flag. The otehr version runs when the space key is pressed, even if the project isn't running at that point! That's a huge difference and it's important you understand that.

A lot of coding is attention to detail especially if copying code from elsewhere or asking a question here
gubzgubz
New Scratcher
9 posts

Manage collision between 2 sprites

deck26 wrote:

So what you had was a script that checked for space as soon as the project started (green flag clicked) but not after that so that script virtually always finished running a split second after you clicked the green flag. The otehr version runs when the space key is pressed, even if the project isn't running at that point! That's a huge difference and it's important you understand that.

A lot of coding is attention to detail especially if copying code from elsewhere or asking a question here

This is very helpfull
Thank you

Powered by DjangoBB