"Decoding" a variable

My game has tons of randomized content since it would be too much trouble to create a unique set of variables for each event I made a system of "keys" (similar to Minecraft) in which each number would contain a certain parameter value.
Now the question is how do I decode them a.k.a. check each numeral's (digit) value. Imagine a variable has a value of 123 where 1 would be the difficulty, 2 levels number and 3 anything else, etc.
I'm not an expert, but I hope I managed to explain myself.
You can 'decode' a variable like this using a modulo operation, but using an array to store multiple values in a single variable would be so much more practical. I'm not particularly knowledgeable on javascript, though, so I can't help you any further with that.
If you are working with numbers, a popular way is to use division and modulo operators (modulo being the remainder of a division). (Edit: Too slow 🙂 )

So for example, 123 / 100 would be 1.23 (or 1 after rounding down), and 123 % 100 would be 23 (remainder).
Game variables used in event commands are automatically rounded down in MV, other variables you might use in scripts or plugins you would have to round down yourself.

Keep in mind that numbers in Javascript have a fixed accuracy and can only store a total of ~15 decimal digits before becoming inacurate. If you need your key to store more information you can use a string or an array/object for that (or multiple variables).

You could maybe also look into a plugin for "Self Variables" or "Self Data" (I know there was a popular option for this for the VXAce, no idea how MV fares here though).
So I'll need to find a plugin that could check the variable's digits(had no luck so far) value or some knowledge of Javascript?
I've read something about strings and modulo operators, but I still have no idea how to use them in order to get the effect I want 🙁
I did not understand it well, but I believe that you want to separate the digits of a variable in others.

Let's consider that the variable reaches a maximum of 9999, thus having a maximum of 4 places.

You can do this with a simple Javascript command, but if you need to do it for events, it would be like this:
Code:
◆Comment:---------------------------------------------------------
◆Control Variables:#0025 MyNumber = 5423
◆Comment:---------------------------------------------------------
◆Control Variables:#0021 A*** = MyNumber
◆Control Variables:#0022 *B** = MyNumber
◆Control Variables:#0023 **C* = MyNumber
◆Control Variables:#0024 ***D = MyNumber
◆Comment:---------------------------------------------------------
◆Control Variables:#0021 A*** /= 1000
◆Control Variables:#0022 *B** /= 100
◆Control Variables:#0023 **C* /= 10
◆Comment:---------------------------------------------------------
◆Control Variables:#0021 A*** %= 10
◆Control Variables:#0022 *B** %= 10
◆Control Variables:#0023 **C* %= 10
◆Control Variables:#0024 ***D %= 10
◆Text:None, Window, Bottom
:    :\v[21],\v[22],\v[23],\v[24]

The digit of place "D" does not need the split operation.

If you need to work with a larger variable let me know, that I make a command via Javascript or a mini-plugin.
I see. Cool! Thanks! This should work for now!
Thread closed

This thread is being reopened at OP's request.

I have a problem. My variables don't get rounded automatically(maybe cause they're placed in a common event?). I'm using Math.round($gameVariables.value(X)) script call, but it won't work properly if the decimals have values superior to 0.5
Any numeric value stored in $gameVariables is automatically truncated (rounded down), so Math.round() won't do anything since the value is already round in the first place.
Try using Math.ceiling or Math.floor if you want to round them
Try using Math.ceiling or Math.floor if you want to round them
Math.floor works great! Thanks!
Any numeric value stored in $gameVariables is automatically truncated (rounded down)
It doesn't work like that for me. Tired of explaining that :0 Plus I need those decimals for other purposes.
Thread closed
It doesn't work like that for me. Tired of explaining that :0 Plus I need those decimals for other purposes.
Do you need to use fractional numbers?
If so, try the multiplication operation.
Example:
JavaScript:
var num_data=128.51;
num_data*=100; //return 12851

Assuming that you will have fractional numbers with up to 2 digits:
128.51 is 0,0,0,1,2,8,5,1
60.23 is 0,0,0,0,6,0,2,3
0.5 is 0,0,0,0,0,0,5,0

Now if you need to separate data for different information in the same variable it gets more complex:
split-data.png

It would be better to store this data in an Array with pure Javascript and then distribute it in game variables.
I don't know if it is worth doing this as a single variable.

Original thread: https://forums.rpgmakerweb.com/threads/decoding-a-variable.134883/