ChoiceScript’s modulo operator is changing from a simple percent sign % to the word modulo.
If you’ve written code like this:
*set remainder X % 12
You should upgrade to the latest ChoiceScript on github and use this instead:
*set remainder X modulo 12
What's a modulo?
In 2011, I added an advanced operator to ChoiceScript, the “modulo” operator. Here’s how I described it in the Advanced ChoiceScript guide.
You can also use the modulo operator “%” to calculate the remainder after taking a division. Modulo is pretty weird, but it’s has two particularly interesting uses. First, you can check whether a number X is evenly divisible by a number Y by checking whether
X % Y = 0. Second, you can use it to get the fractional part of a number X, the stuff that comes after the decimal point, by calculatingX % 1. For example,3.14 % 1 = 0.14.
modulo is the new modulo
Now, instead of a percent sign % you should use the word modulo as the operator.
Here’s the updated documentation:
You can also use the
modulooperator calculate the remainder after taking a division. Modulo is pretty weird, but it’s has two particularly interesting uses. First, you can check whether a number X is evenly divisible by a number Y by checking whetherX modulo Y = 0. Second, you can use it to get the fractional part of a number X, the stuff that comes after the decimal point, by calculatingX modulo 1. For example,3.14 modulo 1 = 0.14.
Why change it?
I realized recently that I made a terrible mistake using a percent sign % as the modulo operator; it’s too close to the much more commonly used FairMath operators %+ and %-.
That means that when you want to do this:
*set strength %+ 20
it’s too easy to forget to type a + or a - and do this:
*set strength % 20
ChoiceScript won’t flag that as an error, because it is valid (but baffling) code. It means the same thing as:
*set strength strength % 20
That means: take the current strength, divide it by 20 and compute the remainder. So if your Strength was 50, *set strength % 20 would set your Strength to be 10. That’s almost certainly not what you wanted.
As of the latest version of ChoiceScript, both % and modulo work, but I’ve updated the Quicktest tool to print a warning if it catches you using % as a modulo operator. The warning will link back to this forum thread, inviting you to fix it by replacing your % with the word modulo.
At some point in the future (months from now, at least; maybe a year?) I’ll probably make a breaking change to ChoiceScript to remove the old % operator entirely. In that case, any use of % will be flagged as an error.
FairMath Isn't Changing
We’re not changing FairMath at all. *set strength %+ 20 still works the same way it used to.
If you don’t already know what “modulo” does, you’ll probably never need it, so don’t worry about it.


