0 votes
by (1.1k points)
A question about Math and percentage in sugarcube, I would like to know how to increase or decrease values in percentages.

E.g. | Imagine that the protagonist gains an "elite warrior" skill from this skill each monster that he defeats give him more 10% the value of the experience. These values are extremely variable, from 100 to 300.

This also applies to lower values, such as 5% reduction of damage when using a shield.

1 Answer

+1 vote
by (2.4k points)
selected by
 
Best answer

If I've understood it correctly, you want to modify a base value for a given percentage and the add or substract it to another value, right?

Adding a 10% to a value is the same that multiplying it by 1.1, and reducing it by a 5% is multiplying it by 0.95. You can make this operation in a <<set>> like this:

<<set $baseExp to 1000>> -->The exp normally gained
<<set $playerExp to 0>> -->The exp the player has

<<set $playerExp to $playerExp + ($baseExp * 1.1)>> -->The player gains the base exp plus a 10% bonus


<<set $baseDamage to 100>> -->The damage the enemy normally does
<<set $playerHealth to 500>> -->The player's Health

<<set $playerHealth to $playerHealth - ($baseDamage * 0.95)>> -->The player's health after receiving an attack with a 5% reduced damage.

 

by (1.1k points)
That's it, thanks! Math has never been my strong point but working with the code requires me to get better at it.
...