Discuss Scratch

WildRiolu
Scratcher
3 posts

How to stop a value from going under 0?

I am currently making a clicker game on scratch, but i need a data value to not go under 0 so I can prevent cheating.

How do i make a data value impossible to go under 0?
deck26
Scratcher
1000+ posts

How to stop a value from going under 0?

Depends which part of your project changes it? If it always changes by 1 only allow it to happen if the value is currently greater than 0. If it changes by a variable amount you have to do a little more but it's still fairly easy.
inlanoche
Scratcher
42 posts

How to stop a value from going under 0?

you can also do a test if the result of a change would put the value below zero:

ifinitValue-subValue<0thensetdataValueto0elsesetdataValuetoinitValue-subValue

This way, before the calculation is applied you can verify the result is not lower than expected.

Last edited by inlanoche (Sept. 14, 2016 17:44:32)

scubajerry
Scratcher
1000+ posts

How to stop a value from going under 0?

Poof

Last edited by scubajerry (Sept. 14, 2016 17:45:10)

WildRiolu
Scratcher
3 posts

How to stop a value from going under 0?

Thank you all for your answers. But I had figured it out on my own after I posted this using something similar to what inlanoche used.
Thanks.
If you want you can check out what I made with it. (Doge Clicker)

Last edited by WildRiolu (Sept. 14, 2016 19:31:01)

KJtheDJ
Scratcher
27 posts

How to stop a value from going under 0?

Theres a way more simple way to do it



whenclickedforeverifData<0thensetDatato0

Last edited by KJtheDJ (Sept. 14, 2016 23:40:39)

MegaApuTurkUltra
Scratcher
1000+ posts

How to stop a value from going under 0?

KJtheDJ wrote:

Theres a way more simple way to do it



whenclickedforeverifData<0thensetDatato0
yes, and more CPU-intensive
asivi
Scratcher
1000+ posts

How to stop a value from going under 0?


Last edited by asivi (Feb. 9, 2018 21:07:49)

Pop9907
Scratcher
1 post

How to stop a value from going under 0?

thanks!!!
-ShadowOfTheFuture-
Scratcher
1000+ posts

How to stop a value from going under 0?

Pop9907 wrote:

thanks!!!
Please don't necropost. This topic is from 2016 and has already been resolved. Thanks!

Reporting topic to be closed.

Last edited by -ShadowOfTheFuture- (Feb. 9, 2018 20:58:18)

Powered by DjangoBB