MZ How to obtain individual digits of number stored in a variable?

In my game, the player in order to open a chest must input a 4 digit number. The number generates via an auto-run event when entering the map. What I intend is this: the first 2 digits were written down by another character as a clue and left for the player to find. The other 2 digits will be hinted at at another part of the map (ie. a calendar with a certain day of the month marked or something like that).

For the clues, I need to extract the first two and last two digits of the number so that I can integrate them into the 'puzzle' hints. How do I go about doing this?
You can use Div (integer division) for high values, and Mod (remainder after division) for low values.

Let's say the entered value is 1234:
  • Control Variables -> Div -> 100 => this would give 12.
  • Control Variables -> Mod -> 100 => this would give 34.
(You'd Set a new variable equal to the original variable, then do Div/Mod on that new variable.)

Edit: or you could just generate & store each pair of digits in its own variable. When checking vs player input, you can combine the values, e.g. "is 100 * {12} + {34} - {Player Input} equal to zero?".
You can use Div (integer division) for high values, and Mod (remainder after division) for low values.

Let's say the entered value is 1234:
  • Control Variables -> Div -> 100 => this would give 12.
  • Control Variables -> Mod -> 100 => this would give 34.
(You'd Set a new variable equal to the original variable, then do Div/Mod on that new variable.)

Edit: or you could just generate & store each pair of digits in its own variable. When checking vs player input, you can combine the values, e.g. "is 100 * {12} + {34} - {Player Input} equal to zero?".
Ok thanks, I'll do that.
another way if its dynamic in the way I do it with more numbers is this:

JavaScript:
let gv1 = $gameVariables.value(11).toString();
let gv2 = $gameVariables.value(12).toString();
$gameVariables.setValue(14, gv1 + gv2)

what this does, you can any valie to 11 and 12 elsewhere, on checking, you
run this script and a condition to see if 14 is equal at 1234 (12 in value 11, 34 in value 12)
as toString() make it a string number, so you can add the 2 (12 + 34 = 1234)
otherwise if not a string it will be (12+34 = 46) what you don't want 🙂

only I use 3 and 5 variables with different values that are randomized 🙂

depending how you generate the numbers (all at once or 2 at the time).

Original thread: https://forums.rpgmakerweb.com/threads/how-to-obtain-individual-digits-of-number-stored-in-a-variable.181735/