Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to keep a number value from going to a negative number?

Asked by 9 years ago

I'm trying to make a script where the Number value never goes negative but stays on 0 instead of something like -16.-

0
Please do not submit duplicates of questions. BlueTaslem 18071 — 9y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

The maximum of 0 and a number x will be 0 if x is less than 0, and otherwise it will be x.

Lua implements maximum as math.max:

x = math.max(x, 0)
0 -> 0
1 -> 1
5.9 -> 5.9
-5 -> 0
-0.01 -> 0
Ad
Log in to vote
-1
Answered by
faruque 30
9 years ago

Please can you post the script or explain to problem a bit further.

0
I'm trying to make an ammo script, but everytime someone reloads when the TotalAmmo(Number value) is at 2 and they need 5 for the clip, it takes the 5 so that the TotalAmmo value is -3 instead of 0 and the ammo was taken. ScriptingCon 52 — 9y

Answer this question