Getting the average of variables?

Broyi

Veteran
Veteran
Joined
Jun 30, 2014
Messages
95
Reaction score
45
First Language
Spanish
Primarily Uses
RMVXA
Hello! I need help with setting up a variable.

I need to get the average of four variables, and save that average in a fifth variable, and I have no clue how to do it. :rswt

Also, another question. The average is probably going to be an inexact number. How does RMVXA write it out in a dialogue box? Will it spell out all the numbers it can?
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
@Broyi using the Control Variables event command:
  • set the variable to the fifth variable which will store the final result. set the operation to add. set the operand to variable and select the first variable you will be adding.
  • repeat step one until all four variables have been added into the fifth variable.
  • set the variable to the fifth variable which has the total value of all four variables stored within. set the operation to divide. set the operand to constant and type four in as your value.
if you would like a whole number:
  • set the variable to the fifth variable which has the "inexact number" stored within. set the operation to set. set the operand to script and utilize the following script call, where variable id is equal to the id of the fifth variable containing the "inexact number".
Code:
Math.round($gameVariables.value(variableId));
let me know if this works for you, bud.
 
Last edited:

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
i am pretty confident with this; give us a like if this solves your problem. :)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
I'd like to correct the script call since it's posted in VXAce section :p
Code:
$game_variables[id].round
Replace the "id" with your variable id
 

Broyi

Veteran
Veteran
Joined
Jun 30, 2014
Messages
95
Reaction score
45
First Language
Spanish
Primarily Uses
RMVXA
It worked! Thank you both! :kaojoy:
 

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

Latest Threads

Latest Posts

Latest Profile Posts

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.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,061
Members
137,575
Latest member
akekaphol101
Top