Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » My variables change too much when two sprites touch. PLEASE HELP!
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
when green flag clicked
forever
if <touching [line v] ?> then
change [lives v] by (-1)
end
end
When the sprite touches the line, then the variable ‘lives’ goes down really, really fast! How do I fix this?
- Bogush4
-
Scratcher
95 posts
My variables change too much when two sprites touch. PLEASE HELP!
You could do
wait (...) secs… is the value you want.
- deck26
-
Scratcher
1000+ posts
My variables change too much when two sprites touch. PLEASE HELP!
Or wait until not touching so each touch only counts once.
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
Or wait until not touching so each touch only counts once.I tried this.
when green flag clicked
forever
if <touching [line v] ?> then
change [lives v] by (-1)
wait until <not <touching [line v] ?>>
end
end
But it doesn't seem to work. Maybe I was doing it wrong?
- deck26
-
Scratcher
1000+ posts
My variables change too much when two sprites touch. PLEASE HELP!
Is the project shared? Are you using clones? Is the line doing anything - moving, changing costume?
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
Is the project shared? Are you using clones? Is the line doing anything - moving, changing costume?
I just shared the project, https://scratch.mit.edu/projects/822634343/
I'm not using clones, and the line isn't doing anything
- deck26
-
Scratcher
1000+ posts
My variables change too much when two sprites touch. PLEASE HELP!
None of the apples contain the code I suggested.
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
None of the apples contain the code I suggested.
I did add it, then I removed it because it wasn't working. I could add it back if you like
- Fennelbro
-
New Scratcher
3 posts
My variables change too much when two sprites touch. PLEASE HELP!
None of the apples contain the code I suggested.
I did add it, then I removed it because it wasn't working. I could add it back if you like
The reason i think it wasn't working is because in each one of your heart sprites there's something similar to:
when I receive [L2 v]
hide
change [lives v] by (-1)
Basically as long as you are broadcasting L2 (or any other one) it is changing lives by -1.
You can solve the problem you're having by removing
change [ lives v] by (-1)from each of your hearts and using the code that @deck26 suggested for your apples.
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
None of the apples contain the code I suggested.
I did add it, then I removed it because it wasn't working. I could add it back if you like
The reason i think it wasn't working is because in each one of your heart sprites there's something similar to:when I receive [L2 v]
hide
change [lives v] by (-1)
Basically as long as you are broadcasting L2 (or any other one) it is changing lives by -1.
You can solve the problem you're having by removingchange [ lives v] by (-1)from each of your hearts and using the code that @deck26 suggested for your apples.
Thanks!
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
None of the apples contain the code I suggested.
I did add it, then I removed it because it wasn't working. I could add it back if you like
The reason i think it wasn't working is because in each one of your heart sprites there's something similar to:when I receive [L2 v]
hide
change [lives v] by (-1)
Basically as long as you are broadcasting L2 (or any other one) it is changing lives by -1.
You can solve the problem you're having by removingchange [ lives v] by (-1)from each of your hearts and using the code that @deck26 suggested for your apples.
Oh, unfortunately it didn't work.
Still seem to be having the same problem
https://scratch.mit.edu/projects/822634343/
- deck26
-
Scratcher
1000+ posts
My variables change too much when two sprites touch. PLEASE HELP!
You have the script in one apple but not the others!
Break the scripts for apple 2 and 3 - just split the scripts from their green flag hat blocks - and you'll see apple 1 is fine. So sort the other apples to match.
Incidentally that's a good debugging trick - break it down into a simpler problem so you can concentrate on one sprite.
Break the scripts for apple 2 and 3 - just split the scripts from their green flag hat blocks - and you'll see apple 1 is fine. So sort the other apples to match.
Incidentally that's a good debugging trick - break it down into a simpler problem so you can concentrate on one sprite.
- medians
-
Scratcher
1000+ posts
My variables change too much when two sprites touch. PLEASE HELP!
It appears to be working for me when I had wait until after changing Lives by -1 before the if statements close, except your lives get set to 0.
The problem there is the heart sprite receives the life 1 broadcast, but also sets lives to 0.

The other heart sprites seem fine.
Edit: Also you should be hiding it only when it game overs, so just change L1 to GameOver and maybe remove set lives to 0 because it's redundant.
The problem there is the heart sprite receives the life 1 broadcast, but also sets lives to 0.

The other heart sprites seem fine.
Edit: Also you should be hiding it only when it game overs, so just change L1 to GameOver and maybe remove set lives to 0 because it's redundant.
Last edited by medians (March 21, 2023 17:35:00)
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
You have the script in one apple but not the others!I completely didn't notice the apple thing lol, thanks
Break the scripts for apple 2 and 3 - just split the scripts from their green flag hat blocks - and you'll see apple 1 is fine. So sort the other apples to match.
Incidentally that's a good debugging trick - break it down into a simpler problem so you can concentrate on one sprite.
- EdjioticIdjit
-
Scratcher
16 posts
My variables change too much when two sprites touch. PLEASE HELP!
@medians and @deck26, thanks, my problem is solved
- Discussion Forums
- » Help with Scripts
-
» My variables change too much when two sprites touch. PLEASE HELP!




