$gameVariables.add truncates numbers. Why?

taarna23

Marshmallow Princess
Global Mod
Joined
Jul 20, 2012
Messages
2,349
Reaction score
4,631
First Language
English
Game_Variables.prototype.setValue = function(variableId, value) {
if (variableId > 0 && variableId < $dataSystem.variables.length) {
if (typeof value === 'number') {
value = Math.floor(value);
}
this._data[variableId] = value;
this.onChange();
}
};


As stated, using $gameVariables.add truncates any number put into it. Is there any particular reason? This comes up from someone else asking how they can use a floating point number with a variable and assigning it with a bit of script did not work (obviously).


I have to say, I really really dislike truncation. If there's some reason it absolutely needs to be an integer, I feel like it should be rounding, at least. But that's the real question - is an integer really needed? Is there some strange thing that would break if it didn't get an integer or something? Seems like a strange choice to me.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,291
Reaction score
11,878
First Language
English
Primarily Uses
RMMV
$gameVariables.add?  Or $gameVariables.setValue?


It's just the way it's been in all the makers - variables are integers.


To get around it, just set it directly and call the onChange function (which causes the map to refresh in case any events are conditioned by the variable):

Code:
$gameVariables._data[id] = 12.9;
$gameVariables.onChange();
 

taarna23

Marshmallow Princess
Global Mod
Joined
Jul 20, 2012
Messages
2,349
Reaction score
4,631
First Language
English
SetValue is probably what I was thinking. I was so in need of coffee this morning that I forgot I hadn't had coffee this morning, if that helps set my frame of mind.


Thanks!
 

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

Latest Threads

Latest Posts

Latest Profile Posts

The universe does not want me to do another letsplay it seems... I keep bumping into problem after problem... Oh well. Still have several days to sort them out.
I now have something new to learn. Lesson suggestions?
Finally with a new PC! Now I can do nice things both coding and gaming
nvidia release the IA paint to lsd landscape simulator
i just try , it very fun
"If the lion knew her own strength, hard were it for anyone to rule her". This would be my custom title if I had enough spaces for it. Coming off of personal pain, I'm glad I found the original quote I've tweaked.

Forum statistics

Threads
93,460
Messages
912,629
Members
122,993
Latest member
hyorex
Top