Getting the average of variables?

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. 😅

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?
@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.
Ok, I'll try it. Thanks, @dbchest !
i am pretty confident with this; give us a like if this solves your problem. 🙂
I'd like to correct the script call since it's posted in VXAce section 😛
Code:
$game_variables[id].round
Replace the "id" with your variable id
@TheoAllen blast! hahaha.
It worked! Thank you both! 😂

Original thread: https://forums.rpgmakerweb.com/threads/getting-the-average-of-variables.88334/