Bizarre CRI glitch

TheGamedawg

Veteran
Veteran
Joined
Aug 29, 2014
Messages
350
Reaction score
133
First Language
English
Primarily Uses
I'm having an odd glitch happen while editing the CRi ex-parameter of some of my characters.  It's only happening with certain classes as well as a few weapons/armors.  Here's what's going on.


Take a look at this part of a character's status screen.  http://imgur.com/unitHzM


The "Chance" status is the CRI rate for the character.  It's suppose to be 15 for this character but it goes into some weird decimal and I don't know how to fix it.  He has one piece of equipment that increases his CRI rate by 1%, but removing it only makes the stat 14.0000000000000... ect.


Strangely, there is another character with a similar issue, but removing the armor for him does fix it.  I've looked into the coding for the classes and nothing is wrong, it's just a really weird bug that's occurring and I can't find a way to fix it.  Only some of the characters are experiencing this problem even though the CRI rate is implemented exactly the same for all of them.  Can anyone help?
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
Are you using an additional plugin that alters the way the status screen looks? I never really looked into MV, but I don't think there was a "critical strike chance" display by default.


Edit: Confused EX-paramters with SP-parameters, but they are still stored as floating point numbers. For example, a critical strike chance of 11% would be stored as  cri = 0.11  internally:


EX-parameters are not stored as integers internally, so it's completely possible to have a critical strike chance of 15.64211% for example. Due to the way those parameters are stored it is possible that operations like "increase by 1%" also result in a very small rounding error.


If the plugin that displays the result does not take care of that and rounds the displayed number accordingly this might lead to such an output.


If you find the code piece responsible for printing the chance to the status window, you should be able to use


Math.round( number )


to round the displayed number to an integer. Alternatively, you can use 


( number ).toFixed( x )


to create a text string of number rounded to x decimal places.
 
Last edited by a moderator:

TheGamedawg

Veteran
Veteran
Joined
Aug 29, 2014
Messages
350
Reaction score
133
First Language
English
Primarily Uses
A am using some plugins, but I tried disabling them all and nothing has changed.  However what you recommended seems to have worked, Thanks!


I don't think an extra millionth of a chance to get a critical hit is going to matter in the grand scheme of things, but I'm still curious as to if there is a way to internally fix the rounding error.
 

TheGamedawg

Veteran
Veteran
Joined
Aug 29, 2014
Messages
350
Reaction score
133
First Language
English
Primarily Uses
Are you using an additional plugin that alters the way the status screen looks? I never really looked into MV, but I don't think there was a "critical strike chance" display by default.


Edit: Confused EX-paramters with SP-parameters, but they are still stored as floating point numbers. For example, a critical strike chance of 11% would be stored as  cri = 0.11  internally:


EX-parameters are not stored as integers internally, so it's completely possible to have a critical strike chance of 15.64211% for example. Due to the way those parameters are stored it is possible that operations like "increase by 1%" also result in a very small rounding error.


If the plugin that displays the result does not take care of that and rounds the displayed number accordingly this might lead to such an output.


If you find the code piece responsible for printing the chance to the status window, you should be able to use


Math.round( number )


to round the displayed number to an integer. Alternatively, you can use 


( number ).toFixed( x )


to create a text string of number rounded to x decimal places.




Do you think there are any other ways to fix this?  Again, your solution works pretty well but I think that somewhere in the code the tiny decimal difference is still being calculated.  Maybe there's a way to round the number as it's being calculated internally.  What do you think?
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
There is no extra calculation going on for the decimal difference.


The reason the error can appear is because applications represent numbers in the base-2 numeral system, since that's what practically all computers are optimized to work with. While 0.01 is easy to represent in the base-10 system, it becomes periodic when expressed in the base-2 system and has to be rounded.


Summing up multiple rounded values might just increase the error to a point where it is actually displayed when converting the result back into a decimal number.


You could improve the precision by choosing a representation that does not have to be rounded and change the calculations accordingly. However...


- The random number generation function is probably not that perfect to allow a "perfect" 15% chance anyway


- Since we are talking about randomness the actual number of critical strikes will vary wildly


- We are still far from talking about a millionth here (a millionth only has 5 zeros after the radix point :) )


May I ask what you did exactly to fix the error? As I mentioned, I couldn't find the critical strike chance displayed anywhere in an empty project, so I'd really like to know where you found the code piece or which script you used. :)
 

TheGamedawg

Veteran
Veteran
Joined
Aug 29, 2014
Messages
350
Reaction score
133
First Language
English
Primarily Uses
There is no extra calculation going on for the decimal difference.


The reason the error can appear is because applications represent numbers in the base-2 numeral system, since that's what practically all computers are optimized to work with. While 0.01 is easy to represent in the base-10 system, it becomes periodic when expressed in the base-2 system and has to be rounded.


Summing up multiple rounded values might just increase the error to a point where it is actually displayed when converting the result back into a decimal number.


You could improve the precision by choosing a representation that does not have to be rounded and change the calculations accordingly. However...


- The random number generation function is probably not that perfect to allow a "perfect" 15% chance anyway


- Since we are talking about randomness the actual number of critical strikes will vary wildly


- We are still far from talking about a millionth here (a millionth only has 5 zeros after the radix point :) )


May I ask what you did exactly to fix the error? As I mentioned, I couldn't find the critical strike chance displayed anywhere in an empty project, so I'd really like to know where you found the code piece or which script you used. :)
"Chance" is just the jargon my game is using for for the critical hit chance.  In the code that displays the status menu, I put a little space in between 2 of the normally displayed parameters to put this.


this.changeTextColor(this.systemColor());
this.drawText('Chance', x, y2, 200, 'left');
this.resetTextColor();
this.drawText(Math.round(this._actor.cri*100), x + 70, y2, 60, 'right');


If you take away "Math.round" you get the rounding error.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Do you think there are any other ways to fix this?  Again, your solution works pretty well but I think that somewhere in the code the tiny decimal difference is still being calculated.  Maybe there's a way to round the number as it's being calculated internally.  What do you think?


You'll have to round all the numbers yourself, since the game doesn't do that automatically.


It would be up to you to choose when numbers should be rounded to avoid rounding errors.


If the different is insignificant (ie: it doesn't affect the player if you don't show that 0.0000000000001), then you can just round it before it is drawn to the screen.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,078
Members
137,580
Latest member
Snavi
Top