# Modulo Operations in Smile Game Builder

A Modulo operation finds the remainder after dividing one number by another number. It’s better known as mod or modulus, and in some programming languages, such as C++ and JavaScript, it’s represented by a percentage sign (%).

To output individual parts of numbers – 1000’s, 100’s, 10’s and 1’s – for such things as HUDs to display numbers in a graphical representation, Smile Game Builder uses Substitute Divided Remainder in the Advanced Variable Box Op, which is the modulo operation.

So, say you wanted to use the 10’s value from a number, but not the 1’s or any remainders after it, you can extract it as a single value using this function. In this article, variable manipulation uses the Advanced Variable Box Op.

### Random Number

For the purposes of this article, and to see it in action, the first step is to create a variable to generate a random number.

• Use the Random Number command in the Advanced Variables to generate a random number range. The regular Variable Box will just add a random number to the existing number. However, we want to generate a new random number each time.
• Assign a variable with a random number between 0 and 999.

### Units or 1’s

To calculate the units, the formula is:

Number % 10

Which simply divides the number by 10 and outputs the remainder.

• Store the random number variable into another variable for the 1’s.
• Add another Advanced Variable Box to modify the 1’s variable to a fixed value of 10, and set the Substitute divided remainder as the operation.

### Tens or 10’s

For caluclating the tens, the modulus operation is:

(Number % 100) / 10

• Once again, set a variable for the 10’s to the same as the random number.
• Substitute the remainder with a fixed value of 100.
• And divide the result by 10.

At this point, you may start to see a pattern emerging. This is a surefire way of calculating and outputting much larger numbers…

### Hundreds or 100’s

The formula for the hundreds is:

(Number % 1000) / 100

• So, as with the tens, a variable is created, this time for the 100’s, and set to the same as the random number.
• The remainder is set.
• And divide the result by 100.

### Thousands or 1000’s

If you’re going to use higher numbers in HUDs, such as for stats, you’ll also need thousands as well.

The modulo operation to calculate this is:

(Number % 10000) / 1000

This is set up in the same way as the previous numbers using the variable to store the 1000’s.

### Final Product

The final product will look like this:

Each time the random number updates, it’ll separate the value into its component parts, returning an integer for the thousands, hundreds, tens and units so that they, in turn, can be used to update graphics referencing the number.

You can check to see if it’s running properly by pressing F5 during playtesting and monitor each variable.