Discuss Scratch

BobbyF
Scratcher
20 posts

Score Variable Isn't Working

So I've been working on this Easter Egg Hunt game (too bad it didn't make it in time for an Easter upload), and somewhat recently, the “Score” variable just decided to stop working on me Sure, if I were to manually add to the variable, the number would go up, but with the scripts I have, it won't affect the variable at all. Occasionally it would, but the counting would be so imprecise. So then i decided to work my way around it, and use number sprites instead of the scoring system. But guess what? That ended up not responding either I very much hope someone can help me find the solution to my problem. If screenshots or explanations of the scripts are needed, I shall provide. I'll do anything it takes to get this mystery figured out.
-Spectrum
Scratcher
500+ posts

Score Variable Isn't Working

Can you please share the project and provide a link so I can see what's wrong? :-)
BobbyF
Scratcher
20 posts

Score Variable Isn't Working

Sure! Here's the project: https://scratch.mit.edu/projects/103279113/
Thanks for noticing my forum post
-Spectrum
Scratcher
500+ posts

Score Variable Isn't Working

BobbyF wrote:

Sure! Here's the project: https://scratch.mit.edu/projects/103279113/
Thanks for noticing my forum post

Where are you actually changing the score? I might just be blind, but I couldn't find anywhere where you change the “Score” variable by a value. What do the “Egg Counter” variables do? Are you sure you're not getting them mixed up and changing the wrong variables?

Sorry for all the questions

BobbyF
Scratcher
20 posts

Score Variable Isn't Working

Oh, sorry, that's my fault I guess when I had moved to the “number sprite” method, I had scrapped the scripts for the variable. I just went back and readded the scripts for the Score variable (of course they still don't work though). The “Egg Counter” variable just tell the eggs how long they have til they have to disappear, and the “Egg Chance” variables determine what color they will be, or how much they will add to the Score variable. If you can't figure out the problem, that's fine, I appreciate the support anyways
ErnieParke
Scratcher
1000+ posts

Score Variable Isn't Working

The problem with your project is probably an oversight: You cannot be touching a sprite that is hiding. You can easily test this for yourself by making a new Scratch project, adding an apple sprite, hiding it, moving the Scratch cat over the apple sprite, and asking the Scratch cat is he is touching the apple. He will say “false”.

In your project, you have three pieces of code that rely on touch.

1). The egg count down timer, which hides the egg.
2). The score increase script.
3). Some third script which I forget about at the moment.

Let's say you pick up an egg. Script 1 will hide the egg. However, scripts 2 and 3 will then think that you are not touching the egg, and they will not activate!

The way to fix this is to combine your scripts, or to make a variable indicating that you touched the egg. If you combine your code, try this:

repeatuntiltouchingHuman?oreggcountdown1<0changeegg countdown 1by-0.5wait0.5secsiftouchingHuman?thenbroadcastScore 10Replace with the correct broadcast name.. . .Any other code.

Make sense?

Showing,

ErnieParke

Last edited by ErnieParke (March 28, 2016 21:06:47)

-Spectrum
Scratcher
500+ posts

Score Variable Isn't Working

BobbyF wrote:

Oh, sorry, that's my fault I guess when I had moved to the “number sprite” method, I had scrapped the scripts for the variable. I just went back and readded the scripts for the Score variable (of course they still don't work though). The “Egg Counter” variable just tell the eggs how long they have til they have to disappear, and the “Egg Chance” variables determine what color they will be, or how much they will add to the Score variable. If you can't figure out the problem, that's fine, I appreciate the support anyways

Sorry I took so long to reply. I think it's because you can't touch a sprite when it's hiding, and you have 3 scripts that rely on touch. They run at the same time and get confused, because 2/3 of the scripts think you're not touching the egg. The way to fix this is to combine your scripts somehow.

EDIT: Oops! I completely missed ErnieParke's post, and we said nearly the exact same thing! Oh well, Ernie provided a better explanation. Glad you found an answer in the end :-)

Last edited by -Spectrum (March 29, 2016 00:03:03)

BobbyF
Scratcher
20 posts

Score Variable Isn't Working

@-Spectrum @ErnieParke A big thanks to both of you! Good news is that the Score variable is responding and finally works again!….. Well, mostly. Now there's only one tiny error I need to fix before I can release the game. While most of the time, the scripts detect the eggs and add correctly to the Score variable, sometimes, they don't at all. Occasionally I don't see the variable change, or I don't even hear the sound effect play. I uploaded a fixed version of the project recently; if you can help me fix this last tiny problem, the game will be ready to release! https://scratch.mit.edu/projects/103299343/
-Spectrum
Scratcher
500+ posts

Score Variable Isn't Working

Hmm… I tried a few times and it worked fine for me. Since the bug didn't happen to me, I can't be 100% sure where the problem is in the script.

I'm going to take a guess, though, and say that it's because occasionally the egg hides just as you touch it. There's a chance it's the old bug coming back in a new form, though - because of the timing, the three scripts which rely on touching the eggs (the ones that ErnieParke and I brought up earlier) get confused again - one hides the egg so the others don't work. Perhaps you could somehow merge those three scripts together, so they're not all getting mixed up?

I'm not quite sure how to approach that issue, but you could always release the game officially and leave note saying there's a small, rare bug. It can't happen too often if I played the project several times and didn't encounter it. The score went up every time I touched an egg.

So like I said before, experiment and try merge the scripts together if you can, so they're not confusing each other. It's always more efficient to have the smallest amount of scripts possible controlling one function. I wish I could be of more help, but I wasn't able to find the bug… the scripts looked fine when I searched through them.

Aha - I had an idea. I only looked at the scripts in the eggs. While it's unlikely, it is possible that some other script is stuffing things up, which would explain why the bug only happens occasionally - there has to be the right conditions. Now I think about it more, I only played as the female character because she's fastest, (sorry, forgot her name… Hilary or something, right?) so it could be a bug in one of the other players. Are you trying to change the score by one in the player sprites, as well as the eggs? Because sometimes trying to change variables simultaneously messes things up a bit. It could also be due to lag, although that's just a guess.

Phew, that was long. I wish I actually knew what was going on so I could actually give you advice instead of just guessing things…

Good luck!


karstenisgerman
Scratcher
1 post

Score Variable Isn't Working

similar issue. I can't get trump to increase score by 1 when he touches Putin. Can't figure out what I'm missing. https://scratch.mit.edu/projects/199584431/#player
deck26
Scratcher
1000+ posts

Score Variable Isn't Working

karstenisgerman wrote:

similar issue. I can't get trump to increase score by 1 when he touches Putin. Can't figure out what I'm missing. https://scratch.mit.edu/projects/199584431/#player
Please create your own topic rather than necroposting.
Trevor_Nugent
New Scratcher
1 post

Score Variable Isn't Working

Guys… The score variable is messed up. I'm just tryna do a project, and when my dog touches the yellow ball, the score decreases by two only occasionally. What the heck?!

Last edited by Trevor_Nugent (Jan. 8, 2020 15:41:40)

deck26
Scratcher
1000+ posts

Score Variable Isn't Working

Trevor_Nugent wrote:

Guys… The score variable is messed up. I'm just tryna do a project, and when my dog touches the yellow ball, the score decreases by two only occasionally. What the heck?!
Create your own topic and share the project. Necroposting on someone else's topic is not a good way to ask for help.
deck26
Scratcher
1000+ posts

Score Variable Isn't Working

sanvisoo3568 wrote:

I've been having the same problem….wonder why!
score
Perhaps if you did what has been suggested several times and created your own topic and shared the project you'd get more attention.
ksisim
New Scratcher
1 post

Score Variable Isn't Working

So i have made a game and its for an assessment task and basically the sprite has to touch the object for the score to increase by 1. for this game I have to increase by levels, level 1 worked fine but level 2 is messing up and I don't know what to do the score is just spiking!
BobbyF
Scratcher
20 posts

Score Variable Isn't Working

ksisim wrote:

So i have made a game and its for an assessment task and basically the sprite has to touch the object for the score to increase by 1. for this game I have to increase by levels, level 1 worked fine but level 2 is messing up and I don't know what to do the score is just spiking!
Please create a new topic for your issue instead of reviving old threads. Deck26 has already had to tell people this three times so I would like to save them some trouble and encourage you to make your own thread about this so you can easily get more answers at a faster rate.
mjpt2019
Scratcher
8 posts

Score Variable Isn't Working

similar issue. My code isn't changing the output variable, but when I drag it out by hand and click it, it works.

Last edited by mjpt2019 (April 13, 2020 14:19:37)

mjpt2019
Scratcher
8 posts

Score Variable Isn't Working

mjpt2019
Scratcher
8 posts

Score Variable Isn't Working

the encryption works fine, but the decryption is completely bombed
mjpt2019
Scratcher
8 posts

Score Variable Isn't Working

plz help!

Powered by DjangoBB