I want to have a money system and I set everything else up to remove or add money but I don’t know how to lock it so that it doesn’t go below 0 can someone help me?
Where ever you deduct value from your score variable (whatever you call it, put this if statement after it, changing the variables of course.
if score \< 0 then score = 0 end
I’d like to refer you to my other answer to another post of yours: https://forums.coronalabs.com/topic/77147-can-i-have-a-collision-answer/#entry407089
That said, in this particular issue all you are looking for is a conditional check to see if the player has enough money to do whatever it is that they want to do.
local money = 50 local cost = 100 if money \>= cost then print("you've got enough money!") -- then you could deduct whatever the cost was from the money, i.e. money = money - cost else print("you don't have enough money!") end
It really seems like you just need to start learning the basics. Happy coding!
Hi,
You could also clamp it, just as another option.
score = math.max(score, 0)
-dev