KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
447
Reaction score
80
First Language
Portuguese
Primarily Uses
RMMZ
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.
 
Last edited:

Jules98

Veteran
Veteran
Joined
Jul 10, 2017
Messages
339
Reaction score
224
First Language
Dutch
Primarily Uses
RMMV
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.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
608
Reaction score
320
First Language
German
Primarily Uses
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).
 

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
447
Reaction score
80
First Language
Portuguese
Primarily Uses
RMMZ
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 :(
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
968
Reaction score
470
First Language
PT-BR
Primarily Uses
RM2k3
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.
 

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
447
Reaction score
80
First Language
Portuguese
Primarily Uses
RMMZ
I see. Cool! Thanks! This should work for now!
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,647
Reaction score
15,743
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
447
Reaction score
80
First Language
Portuguese
Primarily Uses
RMMZ
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
 

Jules98

Veteran
Veteran
Joined
Jul 10, 2017
Messages
339
Reaction score
224
First Language
Dutch
Primarily Uses
RMMV
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.
 

JGreene

Veteran
Veteran
Joined
Oct 24, 2015
Messages
452
Reaction score
363
First Language
English
Primarily Uses
RMMV
Try using Math.ceiling or Math.floor if you want to round them
 

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
447
Reaction score
80
First Language
Portuguese
Primarily Uses
RMMZ
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.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
6,114
Reaction score
5,860
First Language
English
Primarily Uses
RMVXA

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
968
Reaction score
470
First Language
PT-BR
Primarily Uses
RM2k3
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.
 
Last edited:

Latest Threads

Latest Profile Posts

Streaming some game development! Feel free to drop by!
SF_Enemy1_4 added!
index.php

Who wants to see me mock my brother's story? Brother story: thus he summoned a mighty twenty foot lizard. My Comment: Godzilla is attacking the city! As bad as these 4 are at shopping I wouldn't be surprised if Jun didn't proudly return with a chamber pot on her head. "Look at this helmet I got for 1,000 gold!"
Apparently I'm a grandpa now.

20220128_181216.jpg20220128_181227.jpg
Sales Goal of Learn RPG Maker MV at 64% now! :kaopride:

Forum statistics

Threads
118,809
Messages
1,118,875
Members
155,989
Latest member
mastercheikh
Top