Simple math with variables and script calls?

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
985
Reaction score
1,277
First Language
Swedish
Primarily Uses
RMMV
Okay, maybe this isn't really Javascript? Maybe it is? I dunno because I'm a complete chump when it comes to programming (and math in general), but I think this might be the correct section of the forums to ask this. At least most people on this board probably know how to do what I'm asking.

So, I want to do some simple math calculations using the values I got stored in different variables, and put the answer into a new variable. Basically math similar to what you could do in the damage formulas (add, subtract, multiply, divide). I think this should be doable with a script call, correct?

What I don't know is how to do it. I've never really done something like it before in MV and it's probably pretty straight forward but after googling for a while, I couldn't find an answer to how to write the formulas.

Here's one of my non-working stabs at doing some math with the control variable and script call commands:

$gameVariables.value(105)-$gameVariables.value(104)*10-$gameVariables.value(103)

...didn't work. :kaocry:

Thanks in advance.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,339
Reaction score
12,841
First Language
English
Primarily Uses
RMMV
So you can use the Control Variables event command, putting the variable you want the result in as the top part, and the formula in the script box.

If you do the following:
Code:
Control Variables [100: result] = Script: $gameVariables.value(105) - $gameVariables.value(104) * 10 - $gameVariables.value(103)
that will give you a result, but it might not be what you expect.

Remember the mathematical order of operations - the multiply ($gameVariables.value(104) * 10) is the first thing that will happen. Then that will be deducted from variable 105, and finally variable 103 will be deducted from the result.

So if you have var 105 = 10, 104 = 5, and 103 = 2, it'll be this:
10 - 5 * 10 - 2 which is
10 - 50 - 2 which is
-38

If you can't figure it out from there, give us examples of what's in the variables, what you expect to get as a result, and what you're getting as a result.
 

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
985
Reaction score
1,277
First Language
Swedish
Primarily Uses
RMMV
@Shaz
Thank you. Actually, I was so heavily focused on the formula that I didn't notice that the rest of my eventing was screwed up and didn't work - which is why I didn't get any result at all. After you pointed out the order of operations I corrected the formula and it works as intended for now.

Follow up question though. Is it possible to add a "if the result is above/below this, then show X instead?".
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,339
Reaction score
12,841
First Language
English
Primarily Uses
RMMV
I would need to see the context, as what I've given you is just a formula to calculate a variable - nothing about conditions in there. Can you post a pic of your event?
 

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

Latest Threads

Latest Profile Posts

JDgoldvox wrote on Mr. Detective's profile.
hey, could u help me with a problem? basically, How do I delete a character from a map after a cut scene is over? I am really new with RPG maker MV. Please help!
The most rewarding part of making custom body character parts is absolutely not making the masks work. Somebody please put me out of my misery.
Any commercial devs here ever mess with Gamejolt? Been contemplating making my games available there but don't know if it's worth the effort or not.
Social distancing taught me of how much of not a loner I am. Dammit, I miss seeing my friends...
Happy 4th of July all. Anybody have plans? Mine here is staying home away from the virus. Still a nice 3 day weekend.

Forum statistics

Threads
99,263
Messages
963,617
Members
130,856
Latest member
superfluffy
Top