Negative variables

ChoiceScript has no way to tell if you’re trying to use a negative number, or subtract when you enter - 100. Generally it’s recommended that you avoid negative numbers.

There are two normal solutions to this problem, then a third non-recommended one:

Rezero

Use a higher number as you “zero” and calculate from there. For example, if you know income is never going below 1000, rather than start it as *create income 0, you use *create income 1000, and rather than *if income <= -100, you check *if income <= 900 (and your display of income just becomes ${(income-1000)}, if you need to).

Convert it

Go to a subroutine whenever you *set income (either adding or subtracting), you’ll also need to check (off the top of my head and untested):

*if debt > 0
  *set income - debt
  *set debt 0
*if income < 0
  *set debt (0 - income)
  *set income 0

Use work around (Not recommended—may not work in all cases)

To ‘use’ a negative number, use (0-foo) instead. So, for that *if, you’d need to use *if income <= (0-100). (Alternatively to (0-foo), you can also use "-foo" as pointed out by @Szaal below.)

2 Likes