Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how do you prevent negative numbers?
- laithman
- Scratcher
5 posts
how do you prevent negative numbers?
in my game MoneySimulator2018 (heres the link: https://scratch.mit.edu/projects/236279103/) in the shop when you try to get an upgrade but you don't have enough money, it just gives you the upgrade and the cash variable goes into negative numbers and I don't really want that. does anybody have a script to prevent negative numbers?
- deck26
- Scratcher
1000+ posts
how do you prevent negative numbers?
Or, potentially simpler to understand and one less operation for Scratchif <((cash) - (cost of upgrade)) < [0]> then
say [not enough cash]
else
say [here ya go!]
end
Also, you didn't share the project so I couldn't actually look to see if something else was happening.
if <(cash) < (cost of upgrade) > then
say [not enough cash]
else
say [here ya go!]
end
- adsuri
- Scratcher
1000+ posts
how do you prevent negative numbers?
https://scratch.mit.edu/projects/236279103/) in the shop when you try to get an upgrade but you don't have enough money, it just gives you the upgrade and the cash variable goes into negative numbers and I don't really want that. does anybody have a script to prevent negative numbers?Maybe like this in my game MoneySimulator2018 (heres the link:
when this sprite clicked
if <<(cash) = (cost)> or <(cash) > (cost)>> then
upgrade
else
say [not enough cash] for (2) secs
end
Last edited by adsuri (July 27, 2018 14:25:22)
H He
Li Be B C N O F Ne
Na Mg Al Si P S Cl Ar
K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr
Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe
Cs Ba Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn
Fr Ra Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og
La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu
Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr
- ShinigamiBlacky
- Scratcher
100+ posts
how do you prevent negative numbers?
youre too late…https://scratch.mit.edu/projects/236279103/) in the shop when you try to get an upgrade but you don't have enough money, it just gives you the upgrade and the cash variable goes into negative numbers and I don't really want that. does anybody have a script to prevent negative numbers?Maybe like this in my game MoneySimulator2018 (heres the link:when this sprite clicked
if <<(cash) = (cost)> or <(cash) > (cost)>> then
upgrade
else
say [not enough cash] for (2) secs
end
And deck26s solution is shorter
- adsuri
- Scratcher
1000+ posts
how do you prevent negative numbers?
i was just suggestingyoure too late…https://scratch.mit.edu/projects/236279103/) in the shop when you try to get an upgrade but you don't have enough money, it just gives you the upgrade and the cash variable goes into negative numbers and I don't really want that. does anybody have a script to prevent negative numbers?Maybe like this in my game MoneySimulator2018 (heres the link:when this sprite clicked
if <<(cash) = (cost)> or <(cash) > (cost)>> then
upgrade
else
say [not enough cash] for (2) secs
end
And deck26s solution is shorter
H He
Li Be B C N O F Ne
Na Mg Al Si P S Cl Ar
K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr
Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe
Cs Ba Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn
Fr Ra Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og
La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu
Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr
- laithman
- Scratcher
5 posts
how do you prevent negative numbers?
thanks guys for responses! I will try these. I will also make this project public
- nividhmehra
- Scratcher
16 posts
how do you prevent negative numbers?
when green flag clicked
forever
if <<[cost] < [cash]>> then
say [here ya go!] for (2) secs
broadcast [buyed ]
else
say [not enough cash] for (2) secs
end
end
try this
- Jeph_thegood
- Scratcher
1 post
how do you prevent negative numbers?
Last edited by Jeph_thegood (Jan. 19, 2021 00:38:53)
- cupcake1502
- Scratcher
100+ posts
how do you prevent negative numbers?
when this sprite clickedAnd for a safety measure:
if <(money) > (cost of upgrade)> then
get upgrade
change [money] by (cost of upgrade)
else
say [Not enough money!] for (2) secs
end
when green flag clicked
forever
if <(money) < [0]> then
set [money] to [0]
end
end
define Scratch
forever
Imagine
Procrastinate
Program
Procrastinate
Share
Procrastinate
end
(⌐■-■)
This is Bob. He protects my siggy from evil kumquats by shooting them with a pew-pew.
(っ˘ڡ˘ς)
This is Gem. She protects my siggy from edible kumquats by nom-nomming them.
(#^.^#)
This is Jane. She invites good kumquats into my siggy to have a cup of tea and a biscuit.
The buttons in my siggy were made at Lightning Studios 4.0
ON THE ROAD TO 100 FOLLOWERS! If you would like to, follow me. Thanks. :)
- Nezon
- Scratcher
1000+ posts
how do you prevent negative numbers?
Please don't Necropostwhen this sprite clickedAnd for a safety measure:
if <(money) > (cost of upgrade)> then
get upgrade
change [money] by (cost of upgrade)
else
say [Not enough money!] for (2) secs
endwhen green flag clicked
forever
if <(money) < [0]> then
set [money] to [0]
end
end
This is my signature (it goes automatically under every post I make)! Here is a bit of advice on foruming, by the way. Don't do SAND. SAND means four words.
SAND means Spam, Advertising, Necroposting, and Derailing.
Spam is when a irrelevant message is sent to many places. Wiki Article: Spam
Advertising is when you promote your studios and projects. Wiki Article: Advertising
Necroposting is when you post on a old topic. It distracts other helpers! Wiki Article: Necroposting
Derailing is when you post something that is irrelevant to the topic, like minimodding. It is called thread hijacking. Wiki Article: Derailing(Derailing idea comes from this guy),
in the process of leaving scratch.
bob has been hidden again :(
- RJBERS
- Scratcher
3 posts
how do you prevent negative numbers?
I'm looking for something like this but for Health points do i just copy these but with my variables?
- The_Imaginarium
- Scratcher
1000+ posts
how do you prevent negative numbers?
Please create your own topics instead of posting on other's. I'm looking for something like this but for Health points do i just copy these but with my variables?
- Discussion Forums
- » Help with Scripts
- » how do you prevent negative numbers?