The Tale of the Math Conflict.

Trommer

Villager
Member
Joined
Mar 28, 2014
Messages
12
Reaction score
3
First Language
Swedish
Primarily Uses
Greetings!

I am working on a way to increase a skills damage/healing based upon a variable. But now I have hit a wall. I'm trying to make the variable an % increase.

Aka a variable of 5 should be 5% increase of damage and so on.

So I though it would look something like this:

[increase spell damage by 5%]

Set control variable: [0001: spell damage] = 5

[Very Original Fireball]

(a.mat * 4 + a.mp * 4) + v[1]%

So it would add everything up and then add the extra % on top of that in the end. so if it was 5% it would deal a total off 105% damage.

I have tried almost everything but all I get is errors or the wrong math. I would be very grateful for any thoughts on this.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
  (a.mat * 4 + a.mp * 4) +  (  (a.mat * 4 + a.mp * 4) * v[1]  )   / 100 

I think this will do the trick. Parentheses have the higher priority of the used operators here. 

So let's use them a LOT here just to be sure.

I assume that the damage for your spell is given by  

(a.mat * 4 + a.mp * 4)   

plus 5% of that whole thing in the parentheses if the variable is 5. The variable is variable with id=1

So...

 (  (a.mat * 4 + a.mp * 4) * v[1]  )   / 100  

gives you this 5%

Tell me if that soved the case. 
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
easier and shorter would be the following code:

(a.mat * 4 + a.mp * 4) * (100+v[1])/100The first part is the base damage, multiplied by the total percentage choosen (100% + V[1]%).It is important to have the division by 100 as late as possible, because the integer functions will cut off any remainder from the operation.
 

Trommer

Villager
Member
Joined
Mar 28, 2014
Messages
12
Reaction score
3
First Language
Swedish
Primarily Uses
Thanks man! Amazing work!
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
easier and shorter would be the following code:

(a.mat * 4 + a.mp * 4) * (100+v[1])/100The first part is the base damage, multiplied by the total percentage choosen (100% + V[1]%).It is important to have the division by 100 as late as possible, because the integer functions will cut off any remainder from the operation.
Wait, that returns just the percentage to be added if I am not wrong.

Was that what was asked or was it a bonus x%?

I mean I think the person wanted the base damage PLUS that percentage.

I see what you did there. :) God job.
 
Last edited by a moderator:

Trommer

Villager
Member
Joined
Mar 28, 2014
Messages
12
Reaction score
3
First Language
Swedish
Primarily Uses
To clarify I wanted the 5% to add to the total damage. So let's say I have a skill that deal 100 damage. If I have [increase spell damage by 5%] it would deal 105 damage instead.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
To clarify I wanted the 5% to add to the total damage. So let's say I have a skill that deal 100 damage. If I have [increase spell damage by 5%] it would deal 105 damage instead.
Yes what @Andar wrote is 100% correct. My bad. And it is more simple and easy to read and understand.

(a.mat * 4 + a.mp * 4) * (100+v[1])/100

(100+v[1])/100 equals to 100% + v[1]%

So for V1 = 5 this becomes 105.

So it is (a.mat * 4 + a.mp * 4) * 105%

A very nice way to code it, since it is easier to tweak it if needed and easier to understand. 
 
Last edited by a moderator:

Trommer

Villager
Member
Joined
Mar 28, 2014
Messages
12
Reaction score
3
First Language
Swedish
Primarily Uses
Yes what @Andar wrote is 100% correct. My bad. And it is more simple and easy to read and understand.

(a.mat * 4 + a.mp * 4) * (100+v[1])/100

(100+v[1])/100 equals to 100% + v[1]%

So for V1 = 5 this becomes 105.

So it is (a.mat * 4 + a.mp * 4) * 105%

A very nice way to code it, since it is easier to tweak it if needed and easier to understand. 
Don't worry mate, I am still very glad for you insight. :)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
easier and shorter would be the following code:

(a.mat * 4 + a.mp * 4) * (100+v[1])/100
even shorter:

Code:
(a.mat + a.mp) * 4 * (100+v[1])/100
even shorter:
Code:
(a.mat + a.mp) * (100+v[1])/25
;)
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
Just as a heads-up, the % sign is the "modulo" operator in many programming languages, including Ruby.  Modulo divides one number by another and returns the remainder, so "73 % 10" would return 3.  RPG Maker thought you were trying to use a modulo operation here, but there was no number following the operator, so the formula errored out.

Whenever you want to work with X percent, always use the form X / 100.0 (sometimes 100 will work in place of 100.0, but it can cause serious precision issues), rather than the form X%.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
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

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top