Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Variables in scratch
- Mr_Penguin34
-
50 posts
Variables in scratch
but when I have 5 instead of 10 money it buys it for 5 instead of not allowing them to how do I fix this???
(Something in the store costs 10 money and i have 5 money left when i click BUY the 10 money one it gets rid of 10 BUT than it goes into the negatives (Ex: 2 - 10 = -8) and than the
blocks turn it into 0)
Last edited by Mr_Penguin34 (April 12, 2023 02:06:47)
- medians
-
1000+ posts
Variables in scratch
Uhm, what is it supposed to do, and do you mean when money is equal to 5 instead of 10? Also, why are you automatically setting it to 0 no matter what? Wouldn't that cause problems?
And you can check if the money variable is greater than or equal to a certain value using the not block and the less than block like this:

“Greater than or equal to” basically just means you're equal to the value or greater than it, so basically, you're not less than that value.
Edit: Your code for negatives is not actually making it go to 0 only if it's negative, but rather if it's less than 99 or is equal to 100. Can you send the link to the project to prevent confusion?
And you can check if the money variable is greater than or equal to a certain value using the not block and the less than block like this:

“Greater than or equal to” basically just means you're equal to the value or greater than it, so basically, you're not less than that value.
Edit: Your code for negatives is not actually making it go to 0 only if it's negative, but rather if it's less than 99 or is equal to 100. Can you send the link to the project to prevent confusion?
Last edited by medians (April 12, 2023 02:00:54)
- Mr_Penguin34
-
50 posts
Variables in scratch
@medians no it does not automatically set it to 0 forever it sets it to 0 once instead of forever V
https://scratch.mit.edu/projects/833960610/
click the red cap in the shop
https://scratch.mit.edu/projects/833960610/
click the red cap in the shop
Last edited by Mr_Penguin34 (April 12, 2023 02:02:31)
- medians
-
1000+ posts
Variables in scratch
Okay, it's best to share it in a project and send it here after to prevent confusion because the scratchblocks posted in the original project shows a forever loop. @medians no it does not automatically set it to 0 forever it sets it to 0 once instead of forever
Edit: Can you explain which sprite this is located in?
Last edited by medians (April 12, 2023 02:04:08)
- Mr_Penguin34
-
50 posts
Variables in scratch









































Last edited by Mr_Penguin34 (April 12, 2023 02:03:52)
- medians
-
1000+ posts
Variables in scratch
Okay, I see now.
You'll have to use a method with the if statement and the greater than or equal to workaround that I showed you above. The existing code will go in the if statement.
Do this with the other sprites as well.
You'll have to use a method with the if statement and the greater than or equal to workaround that I showed you above. The existing code will go in the if statement.
Do this with the other sprites as well.
Last edited by medians (April 12, 2023 02:05:15)
- Mr_Penguin34
-
50 posts
Variables in scratch
but when I have 5 instead of 10 money it buys it for 5 instead of not allowing them to how do I fix this???
(Something in the store costs 10 money and i have 5 money left when i click BUY the 10 money one it gets rid of 10 BUT than it goes into the negatives (Ex: 2 - 10 = -8) and than the
blocks turn it into 0)
Last edited by Mr_Penguin34 (April 12, 2023 02:11:51)
- Mr_Penguin34
-
50 posts
Variables in scratch
Where do i put the Uhm, what is it supposed to do, and do you mean when money is equal to 5 instead of 10? Also, why are you automatically setting it to 0 no matter what? Wouldn't that cause problems?
And you can check if the money variable is greater than or equal to a certain value using the not block and the less than block like this:
“Greater than or equal to” basically just means you're equal to the value or greater than it, so basically, you're not less than that value.
Edit: Your code for negatives is not actually making it go to 0 only if it's negative, but rather if it's less than 99 or is equal to 100. Can you send the link to the project to prevent confusion?

- medians
-
1000+ posts
Variables in scratch
You put it in the condition (the part you can put it in) for if statement and replace the cost part with the cost of the item.Where do i put the (yeah)
You'll have to use a method with the if statement and the greater than or equal to workaround that I showed you above. The existing code will go in the if statement.
Do this with the other sprites as well.
Last edited by medians (April 12, 2023 02:11:20)
- Mr_Penguin34
-
50 posts
Variables in scratch







Last edited by Mr_Penguin34 (April 12, 2023 02:18:37)
- Mr_Penguin34
-
50 posts
Variables in scratch





Last edited by Mr_Penguin34 (April 12, 2023 02:19:17)
- medians
-
1000+ posts
Variables in scratch
Sorry, was on a different thing. like in thecode?
And no, that would set it to 0 if they don't have enough money, which would break it. You'd want to do this:

Replace the cost part with whatever is the cost of the item, for all of the sprites.
Last edited by medians (April 12, 2023 02:22:41)
- Mr_Penguin34
-
50 posts
Variables in scratch
Can you remix my project and show me plssss i am Bad reader lolSorry, was on a different project. like in thecode?
And no, that would set it to 0 if they don't have enough money, which would break it. You'd want to do this:
Replace the cost part with whatever is the cost of the item, for all of the sprites.
(if you do THANKSSSS YOUR THE BEST)
- Mr_Penguin34
-
50 posts
Variables in scratch
i am still here (*yawn*)Sorry, was on a different thing. like in thecode?
And no, that would set it to 0 if they don't have enough money, which would break it. You'd want to do this:
Replace the cost part with whatever is the cost of the item, for all of the sprites.
- medians
-
1000+ posts
Variables in scratch
yea my computer wanted to hate me right as i started trying to remix it LOL, so here's the code:i am still here (*yawn*)Sorry, was on a different thing. like in thecode?
And no, that would set it to 0 if they don't have enough money, which would break it. You'd want to do this:
Replace the cost part with whatever is the cost of the item, for all of the sprites.
Green:

Orange:

Yellow:

Blue:

Red:

Replace these with the existing when this sprite clicked codes.
Last edited by medians (April 12, 2023 02:55:04)
- Mr_Penguin34
-
50 posts
Variables in scratch
ummmmm… sry to telll u but i figured it out lol i am so sry but U ARE AMAZING I DID THIS WITH ANOTHER PROJECT AND IT WORKED YESSSSS THXXXXXXyea my computer wanted to hate me right as i started trying to remix it LOL, so here's the code:i am still here (*yawn*)Sorry, was on a different thing. like in thecode?
And no, that would set it to 0 if they don't have enough money, which would break it. You'd want to do this:
Replace the cost part with whatever is the cost of the item, for all of the sprites.
Green:
Orange:
Yellow:
Blue:
Red:
Replace these with the existing when this sprite clicked codes.
- Discussion Forums
- » Help with Scripts
-
» Variables in scratch