Discuss Scratch

Kitten_Boy_10
Scratcher
12 posts

Variable problems

Hi everyone! So I was working on my new game called The game about your random life choices, when, I was trying to make a variable be set to 15 when the sprite was clicked but then it got set to 16 so nothing would appear. Then I made it so they would appear when the variable was 16 but it still wouldn't appear. Here is the code if you would like to look at it.
when this sprite clicked
if <(ButtonClicked) = [14]> then
set [ ButtonClicked] to [15]
end
Then it says that the ButtonClicked variable is 16 instead of 15.
Just to say it, I made 3 main sprites. A button that is on the left, one in the middle, and one on the right. It is on the far left sprite. So it senses what the ButtonClicked variable is so it can change costumes and hide or show them.
The code would look like this.
when green flag clicked
if <(ButtonClicked) = [15]> then
switch costume to [This Random Costume]
The reason I have the variable is because I don't want to make hundreds of messages and then it would just get crowded.

Last edited by Kitten_Boy_10 (March 27, 2024 21:19:02)

PhiPhenomenon
Scratcher
500+ posts

Variable problems

There isn't anything wrong with the script you posted, so there's probably another script that's interfering with it. Can you share your project and link it here?
Kitten_Boy_10
Scratcher
12 posts

Variable problems

PhiPhenomenon wrote:

There isn't anything wrong with the script you posted, so there's probably another script that's interfering with it. Can you share your project and link it here?
Sure! https://scratch.mit.edu/projects/959299469/
Kitten_Boy_10
Scratcher
12 posts

Variable problems

Oh. I just tested it and it works. It might've been a problem I had fixed and not tested before I put this out. Sorry for wasting your time.
PhiPhenomenon
Scratcher
500+ posts

Variable problems

Kitten_Boy_10 wrote:

Oh. I just tested it and it works. It might've been a problem I had fixed and not tested before I put this out. Sorry for wasting your time.
No worries =]
Kitten_Boy_10
Scratcher
12 posts

Variable problems

Kitten_Boy_10 wrote:

Oh. I just tested it and it works. It might've been a problem I had fixed and not tested before I put this out. Sorry for wasting your time.
Wait, nevermind, when I added it to make the ButtonClicked variable change to 16 when it's clicked, it started the problem again. Aren't weird problems just GREAT?
So this is what I did with the variables if you would like to know. When it would be set to 15, it would be set 16 btw
when this sprite clicked
if <(ButtonClicked) = [14]> then
set [ButtonClicked] to [15]
end
if <(ButtonClicked) = [15]> then
set [ButtonClicked] to [16]
end

I'm just going to sleep for a while. I've been trying to fix this for an hour now so…

Last edited by Kitten_Boy_10 (March 27, 2024 21:32:03)

Powered by DjangoBB