# 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.

I doubt you’ll need more than the 1000’s for creating HUDs because if numbers exceed the maximums, they won’t go above that. The only exceptions are probably experience and gold. If you’re determined on using these in a HUD, then following the same pattern by adding zeros to numbers (as seen above).

I won’t go into actually creating HUDs here, as that would take an entire tutorial – perhaps more than one – to cover fully. However, perhaps I will some time in the future.

There are a number of issues with HUDs, notably when numbers refresh on the map. They tend to flicker on-screen, which is distracting and annoying. This is primarily due to the way that SGB uses and synchronizes auto-running events. It cycles through each one until conditions are true, but removes and then replaces the graphical numbers according to those conditions.

Additionally, each true condition overrides the previous ones, so another anomaly occurs with trailing zeroes. As an example, if your value is three digits long, the output on-screen should be 000. However, if the number is 7, the preceding zeros are displayed as blanks.

There is, of course, a workaround for this, but it isn’t reliable or efficient. I’ll put that in another tutorial some time in the future when, hopefully, I’ll have a proper fix for it.

# No Smile Game Builder Tutorial This Week

There’s no Smile Game Builder Tutorial this week!

### Otherworld SGB: Through the Veil

This is primarily because of development on Otherworld SGB: Through the Veil.

It’s a project I wanted to create for a long time and, with everything I now know of SGB (including through the tutorials), it’s achievable.

Many of the techniques I demonstrated in some of the tutorials will also be used in Otherworld SGB.

### Time Flies When You’re Having Fun!

You can have the BEST time management skills in the world, but Time is a hungry, fickle mistress, who will throw at you things that consume the most time, thereby, distracting you.

And, despite having 11 days off, they went by far too quickly. Everything I’d intended to achieve during this time was very particular, with each item allotted a specific timeframe.

Time is a hungry, fickle mistress, who will throw at you things that consume the most time…Companion Wulf
However, as always, things like debugging and designing graphics often means that you’ll go over your allocated time slots.

Unfortunately, this means 3 of the planned showcases (including SGB resources and games) have been pushed back.

I’m back to work tomorrow, with the usual routine of having 2-3 days to work on anything project- or game-related. It’s NOT the "job of my dreams" – game development is! – but, hey, it pays the bills!

# Smile Game Builder Tutorial #28 – Tips & Tricks (Combat)

This tutorial is mainly for combat, but it includes answers to some of the FAQs and how-to’s to some comments I received.

### Action Battle System in SGB

As mentioned in the video, here’s the link to the ABS Battle System.

### Get Jacob’s Assets

You can also obtain the Alien and Drone characters I used in this video from Jacob’s 3D Art, where there’s a free download of his SGB assets and more.