Sorry, i'm not code savvy at all, i have a few questions, sorry if they are kinda dumb lol
Wouldnt it return a Integer number between -2,5 and 2,5 ? could be -2,-1, 0, 1, 2
Exactly, this is why putting a decimal number as the argument has 0 chance of outputting that number. It's always going to be rounded down. (or up for negative numbers, basically the decimal part is chopped off)
Why we're subtracting 2,5 if went through the trouble of making it a integer number? I didnt get this step
It's because
Math.randomInt(5) would output an integer between 0 and 5, so subtracting 2.5 would result in a number between -2.5 and 2.5, but then again it wouldn't work very well.
What i intended to to was to create a formula that would take or add some of the damage, i'm not using the 'Variance' parameter in the interface bc it doesnt effect small numbers, and i want my game to use low numbers
For e.g.
In Lvl 1, i want my character with certain weapon, against certain enemy to hit 3, but sometimes 2 and sometimes 4. But i'd like that number to scalate balanced while in higher levels, so with the same enemy, if the base damage was 20, i'd like it to vary between 18 and 22, and so on
You could use the linear
mx+b formula, one of the first uses of variables you learn in math class, where
x is the level. Yes, this thing is finally going to have a real-life application.
For example, if the minimum damage is 2 at level 1 and 18 at level 10.
f(x) = mx+b; f(1) = 2; f(10) = 18
On
Geogebra, place 2 points with the coordinates being
(level, value), then trace a line between them. The website will give you the formula.
For the minimum in this example, the points' coordinates are (1, 2) and (10, 18), so Geogebra says the formula of the line is 1.7777x + 2.2222.
Same thing for the maximum, 4 at level 1 and 22 at level 10.
The formula, this time, is 2x + 2.
Let's use the go-to formula,
Math.randomInt(max-min) + max with
min = 1.77 * a.level + 2.22 and
max = 2 * a.level + 2.
Your damage formula that scales with the user's level is:
Math.randomInt((2 * a.level + 2)-(1.77 * a.level + 2.22)) + (2 * a.level + 2)