Please help me solve the problem !!!

Joined
May 29, 2018
Messages
1
Reaction score
0
First Language
English
Primarily Uses
N/A
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?
 

Lothloran

Veteran
Veteran
Joined
May 7, 2018
Messages
113
Reaction score
92
First Language
English
Primarily Uses
RMVXA
I could be wrong, but I believe VXA rounds from the decimal, if your product is 13.7 it will round up to 14, if the product is 12.1 it will round down to 12.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
Please edit your post into something meaningful. All threads in this section want help to solve a problem. Many members use the title to decide if it's something they could help with before opening the thread. By giving no indication what the query is, you are reducing your chances of receiving helpful advice.
 

Lord Vectra

Master Eventer
Veteran
Joined
Dec 6, 2015
Messages
211
Reaction score
336
First Language
English
Primarily Uses
RMVXA
Add each of the four variables to the fifth one, and then divide the fifth variable by four. That will give you the result you are looking for.
 

AuralPC

Veteran
Veteran
Joined
May 25, 2018
Messages
48
Reaction score
14
First Language
Chinese
Primarily Uses
RMMV
Create a control variable, select the fifth variable you want the average result to be in, and add following to the script:
Math.round(($gameVariables.value(X)+$gameVariables.value(Y)+$gameVariables.value(Z)+$gameVariables.value(S))/4)

X,Y,Z,S being the ID of the four variables you want the average from.
 

AuralPC

Veteran
Veteran
Joined
May 25, 2018
Messages
48
Reaction score
14
First Language
Chinese
Primarily Uses
RMMV
One more thing, I don't know about VXA, but MV variables do not hold decimals. I believe it would be same for VXA since they both are RPGMAKER.

for example, if the four variables X,Y,Z,S contain the value of 1, 4, 62, 87.

If you do an average of these four number, the result will be 38.5.

But the system will see this as 39, because it will autometically round the number.

So, if, for some reason, that .5 is important to you, and you want to keep it, here is what you may do:

Math.round(($gameVariables.value(X)+$gameVariables.value(Y)+$gameVariables.value(Z)+$gameVariables.value(S))/4*10)

Add times 10 at the end of the script, so the output of the average will be 385 instead of 39.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
@AuralPC The code you have suggested appears to be Javascript. This particular part of the forum is for VX Ace which uses Ruby (RGSS3 to be exact).

In addition:
[dpost]AuralPC[/dpost]
If you want to add something, please edit your earlier post and add in the extra info/comment there.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Using event commands:

Control Variables [0005: Average] = Variable 0001
Control Variables [0005: Average] += Variable 0002
Control Variables [0005: Average] += Variable 0003
Control Variables [0005: Average] += Variable 0004
Control Variables [0005: Average] /= 4

This will give you the average, rounded down.

If you don't want it rounded down, you can do a script call instead of that last command:
Script: $game_variables[5] = $game_variables[5] / 4.0

which will give you a decimal figure. I think.
 

GGZiron

Veteran
Veteran
Joined
Nov 6, 2016
Messages
90
Reaction score
34
First Language
Bulgarian
Primarily Uses
RMVXA
With the event commands only, you can gather the values of all 4 variables into one, then devide on four(as said by Lord Vectra).
If you want to get decimal value, you should use script call, something like that:
Code:
$game_variables[id] /= 4.00
Where you have to replace id with the number of the variable, that contains the total sum of all four variables. To get decimal outcome, is important the number, on which you divide to be decimal, that's why you should write it as 4.00 instead 4. If you don't want decimal outcome, you won't need script call at all, but then your result will be rounded to the lower value.
To display your variable in message box, use this ( inside the text box )
Code:
\v[id]
Where you will have to replace id with the variable id.
AuraIPC, the code you provide is probably for MV, but won't work on Ace.
@Shaz , you ninjaed me ^^. Your post wasn't yet visible for me when i sent mine.
Edit: It seems like @Kes nijaed me too ^^
Edit 2: But thanks to Shaz' answer I seen error in mine (divided on 5, and confused the division operator -_- ), so I fixed it.
 
Last edited:

AuralPC

Veteran
Veteran
Joined
May 25, 2018
Messages
48
Reaction score
14
First Language
Chinese
Primarily Uses
RMMV
@AuralPC The code you have suggested appears to be Javascript. This particular part of the forum is for VX Ace which uses Ruby (RGSS3 to be exact).

In addition:
[dpost]AuralPC[/dpost]
If you want to add something, please edit your earlier post and add in the extra info/comment there.
Sorry, didn't read the forum rules careful enough, will mind this next time.:kaoluv:

@michaeltoan016 and Sorry, I forgot the system for MV and VXA is different.

upload_2018-5-30_16-56-24.png
You will need to select Script for VXA and put following:
$game_variables[5]=($game_variables[1]+$game_variables[2]+$game_variables[3]+$game_variables[4])/4

This will do.

And I just try out, for VXA system, 38.5 will round to 38 instead of 39.

Edit: And thanks to @Shaz and @GGZiron I just tried out. If you want to keep decimal, modify the script to the following will do:
$game_variables[5]=($game_variables[1]+$game_variables[2]+$game_variables[3]+$game_variables[4])/4.00
 
Last edited:

Aoi Ninami

Veteran
Veteran
Joined
Sep 22, 2015
Messages
413
Reaction score
513
First Language
English
Primarily Uses
RMVXA
As a small addendum, if you want the value to be rounded to the nearest integer, simply do this:

Control Variables [0005: Average] = Variable 0001
Control Variables [0005: Average] += Variable 0002
Control Variables [0005: Average] += Variable 0003
Control Variables [0005: Average] += Variable 0004
Control Variables [0005: Average] += 2
Control Variables [0005: Average] /= 4

which is the same as Shaz's solution with an extra line (indicated in bold).
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,047
Messages
1,018,540
Members
137,834
Latest member
EverNoir
Top