Discuss Scratch

Mr_Penguin34
Scratcher
50 posts

Variables in scratch

whenclickedforeverifmoney<99ormoney=100thenset(money)to0
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
whenclicked
blocks turn it into 0)

Last edited by Mr_Penguin34 (April 12, 2023 02:06:47)

medians
Scratcher
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?

Last edited by medians (April 12, 2023 02:00:54)

Mr_Penguin34
Scratcher
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

Last edited by Mr_Penguin34 (April 12, 2023 02:02:31)

medians
Scratcher
1000+ posts

Variables in scratch

Mr_Penguin34 wrote:

@medians no it does not automatically set it to 0 forever it sets it to 0 once instead of forever
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.
Edit: Can you explain which sprite this is located in?

Last edited by medians (April 12, 2023 02:04:08)

Mr_Penguin34
Scratcher
50 posts

Variables in scratch

Last edited by Mr_Penguin34 (April 12, 2023 02:03:52)

medians
Scratcher
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.

Last edited by medians (April 12, 2023 02:05:15)

Mr_Penguin34
Scratcher
50 posts

Variables in scratch

ok!!!
Mr_Penguin34
Scratcher
50 posts

Variables in scratch

whenthisspriteclickedifmoney<99ormoney=100thenset(money)to0
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
whenthisspriteclicked
blocks turn it into 0)

Last edited by Mr_Penguin34 (April 12, 2023 02:11:51)

Mr_Penguin34
Scratcher
50 posts

Variables in scratch

medians wrote:

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?
Where do i put the
medians
Scratcher
1000+ posts

Variables in scratch

Mr_Penguin34 wrote:

medians wrote:

(yeah)
Where do i put the
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.

medians wrote:

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
Scratcher
50 posts

Variables in scratch

Last edited by Mr_Penguin34 (April 12, 2023 02:18:37)

Mr_Penguin34
Scratcher
50 posts

Variables in scratch

Last edited by Mr_Penguin34 (April 12, 2023 02:19:17)

Mr_Penguin34
Scratcher
50 posts

Variables in scratch

Can any one else help me with my problem?
medians
Scratcher
1000+ posts

Variables in scratch

Mr_Penguin34 wrote:

like in the
whenthisspriteclickedifmoney<99ormoney=100thenset(money)to0
code?
Sorry, was on a different thing.
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
Scratcher
50 posts

Variables in scratch

medians wrote:

Mr_Penguin34 wrote:

like in the
whenthisspriteclickedifmoney<99ormoney=100thenset(money)to0
code?
Sorry, was on a different project.
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.
Can you remix my project and show me plssss i am Bad reader lol
(if you do THANKSSSS YOUR THE BEST)
Mr_Penguin34
Scratcher
50 posts

Variables in scratch

medians wrote:

Mr_Penguin34 wrote:

like in the
whenthisspriteclickedifmoney<99ormoney=100thenset(money)to0
code?
Sorry, was on a different thing.
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.
i am still here (*yawn*)
medians
Scratcher
1000+ posts

Variables in scratch

Mr_Penguin34 wrote:

medians wrote:

Mr_Penguin34 wrote:

like in the
whenthisspriteclickedifmoney<99ormoney=100thenset(money)to0
code?
Sorry, was on a different thing.
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.
i am still here (*yawn*)
yea my computer wanted to hate me right as i started trying to remix it LOL, so here's the code:
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
Scratcher
50 posts

Variables in scratch

medians wrote:

Mr_Penguin34 wrote:

medians wrote:

Mr_Penguin34 wrote:

like in the
whenthisspriteclickedifmoney<99ormoney=100thenset(money)to0
code?
Sorry, was on a different thing.
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.
i am still here (*yawn*)
yea my computer wanted to hate me right as i started trying to remix it LOL, so here's the code:
Green:

Orange:

Yellow:

Blue:

Red:

Replace these with the existing when this sprite clicked codes.
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 THXXXXXX

Powered by DjangoBB