How to use variables in Calculations

Status
Not open for further replies.

SteelAngelOpera

Villager
Member
Joined
Aug 30, 2019
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
Hello all,

I've used RPG Maker VX and MV in the past through a friend of mine, this will be the first time I'm using it at my own work station (with the intent to eventually publish my ideas).

I'm writing a script right now where the main character is at a University, and is being tested on various element of game world knowledge. I'd like to be able to track the user's responses, accumulate an average, and at the end of the level present the user with their final grade.

I started tracking using variables, one variable for an individual test score, another for a cumulative one, and a third for the overall average (Points earned divided by total points). I'm having a bit of trouble understanding the calculation, as it would appear that control variables function of the editor only allows me access to two variables at a time. I'd like to take two variables and run them through a function, to spit out the value to a third variable.

I've minor programming knowledge (mostly arduino and robotics) and I'm sure if I really dedicated the time, I could research the necessary programming knowledge to construct my own script, but blah blah I'm a dad and a college student blah blah and simply can't commit the time.

IS THERE an in-editor function I can use to accomplish this goal, or could someone recommend a set up (common event or otherwise) that I can utilize?

Many thanks in advance.

RZ

Additional details

Variables
Quiz Score - variable used to track individual test results (sum of points earned)
Quiz Total - variable to indicate total points on test
Student Total - total points earned through all tests
Total Points - total points available (accumulative)
Student average - Student Total / Total points = Student Average

If/Then argument to assign letter grade based on average
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,041
Reaction score
10,273
First Language
Czech
Primarily Uses
RMMV
Code:
var gv = $gameVariables;
gv.setValue(1, gv.value(2) + gv.value(3));
A demonstration of how you add two variables together and save them in the third onr. I think you should be able to derive what you need from this.
The numbers are variable IDs.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,335
Reaction score
328
First Language
German
Primarily Uses
RMMV
When you use Event Commands, than it could look like this:

Variable 1 "set to" value of Variable 2
Variable 1 add Variable 3

You just do it step by step instead of all at once like in Porygs Scriptline.
You can also always use more variables to temporarly memorize some values for calculations.
 

Wavelength

Pre-Merge Boot
Global Mod
Joined
Jul 22, 2014
Messages
4,611
Reaction score
3,863
First Language
English
Primarily Uses
RMVXA
So what are you having trouble with, the Student Average variable and the ensuing final grade?

Once you already have the Student Total and Total Points Available variables (which should be a piece of cake - add to them either at the end of each individual test, or after each question), all you need to do to get the Student Average is to set it equal to the Student Total variable (this is done using Control Variables just like your other operations), multiply by 100, then finally divide by the Total Points Available variable. That's it!

Then, use nested Conditional Branch commands to determine the grade: If Student Average is >= 90, "Your grade is an A!", Else If Student Average is >= 80, grade is B, Else If SA is >= 70, grade is C, Else If SA >= 60, grade is D, Else grade is F. Just nest each "If" inside of the previous "Else" branch.

Example: Student Total Points is 570, Total Points Available is 700. Set Student Average to 570, then multiply by 100 to 57000, then divide by 700 to 81.43. That's the student's overall average. When plugged into the Conditional Branch, it will return that their grade is a B.
 
  • Like
Reactions: Bex

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,209
Reaction score
6,762
First Language
German
Primarily Uses
RMMV
@SteelAngelOpera
Search for a game called "Variales Guide" here on the forum. One of the links is if you follow the link to the starting point in my signature.

Play that game to the end - it teaches about how to use control variable, with the player being a student in a school about that.
So it'll give you not only a tutorial but also show one way to handle classrooms and tasks for a player.

That part is usable for both MV and Ace, and then comes the third part: you can open the game with Ace (trial is enough if you don't own Ace) to see how the events were made (and eventing is identical between Ace and MV)
 

SteelAngelOpera

Villager
Member
Joined
Aug 30, 2019
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
Maybe this is just confusing because I'm used to running operands through C##.

@Wavelength, I got this part, that's the easy part, but thank you for your input.

Code:
var gv = $gameVariables;
gv.setValue(1, gv.value(2) + gv.value(3));
A demonstration of how you add two variables together and save them in the third onr. I think you should be able to derive what you need from this.
The numbers are variable IDs.
Poryg, this is exactly what I needed! Mods, you may close this post now. I appreciate everyone's input!

@Andar, it's awesome that you've put this together - thank you for teaching the Noobs. The world needs more teachers with experience and less people teaching ignorance.
 

SteelAngelOpera

Villager
Member
Joined
Aug 30, 2019
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
WAIT!
Ran the script, it didn't work.

Script runs thus:

var gv = $gameVariables;
gv.setValue(5, gv.value(3)/gv.value(4));

Afterwards, no operation was completed:
upload_2019-8-30_6-54-26.png

These are variables 1-5 (consecutively), in downward columns. Score didn't divide by Points earned, so no grade was delivered.
 
Last edited:

SteelAngelOpera

Villager
Member
Joined
Aug 30, 2019
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
I tried with both a space between variables and without (scripted above).
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,335
Reaction score
328
First Language
German
Primarily Uses
RMMV
3 devided through 4 is less than 1, which when i remember correctly turns out to be 0.
 

SteelAngelOpera

Villager
Member
Joined
Aug 30, 2019
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
OH. @Bex Yeah, I guess you're right. I am the tards. Lemme multiply by 100 and see what that does for me.
 
  • Like
Reactions: Bex

SteelAngelOpera

Villager
Member
Joined
Aug 30, 2019
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
Yup, that did it. Thanks @Bex . It did not occur to me to work in whole numbers. That's what happens when a math major starts coding.

Thanks again to all, MODS you may now close the thread.

WHAT WE LEARNED:
Using scripting, you can alter the variables using common JS operands by assigning the variables a name value and tweaking them.
You cannot use a number value less than one.

Thanks again, everyone.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
6,023
Reaction score
4,250
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Profile Posts

After 3 and half months of my first long term game being playtested it is now in a more polished state. Now I proudly re-present Path of the Martyrs!
I am feeling better about my update schedule, I feel like I am actually getting consistent work done even if it isn’t big updates.
It's a joy to work on a well-made map. I am not regretting this commission in the least!
I'm currently being attacked by the RPG Maker Hydra: fixing one problem only to have two more rise to take its place.
Hey you! Yeah YOU! Whatcha doin' not backing up your projects? You a masochist or sumthin'? GO BACK UP YOUR PROJECTS! Sheeesh... Didn't think I'd hafta spell it out for yas.

Forum statistics

Threads
94,296
Messages
919,750
Members
124,043
Latest member
mintypatronus
Top