I have found a guide for some damage formulas from FF9 and want to use them
in RMMV which uses Javascript.
Im bad at math and dont know how the Math.random and modulo
works or at least im doing something wrong.
I allways get 0 damage and im sure its because of wrong equation.
Since the Math.random gives a float from 0.00 to 1.00 I thought that would be the problem.
So I've tried to use a random number between 1 and 100 but that didnt helped.
Base = Spell Power - Mag Def
Bonus = Mag + Rnd MOD ([(Lvl + Mag) / 8] + 1)
Damage = Base * Bonus
SPELLPOWER - b.mdf * (a.mat + (Math.random() % ((a.level + a.mat) / 8) + 1))
16 - 2 * (16 + (Math.random() % ((1 + 16) / 8) + 1))
SPELLPOWER - b.mdf * (a.mat + ((Math.random() * (100 - 1) + 1) % ((a.level + a.mat) / 8) + 1))
16 - 2 * (16 + ((Math.random() * (100 - 1) + 1) % ((1 + 16) / 8) + 1))
Somehow this should actualy give a number higher then 0 with the stats i provide.
It was just some wrong set brackets which caused the trouble.
(SPELLPOWER - b.mdf) * (a.mat + Math.random() % (((a.level + a.mat) / 8) + 1))
This works perfectly fine now.
Related
I am trying to get a result that looks like this
"The volume of the cone 261.66 is greater than the volume of the cylinder 785: false."
console.log("The volume of the cone " +(10 / 3 * (3.14 * (5 **2))) "is greater than the volume of the cylinder " +(10 * (3.14 * (5 **2)))): 261 > 785);
EDIT: Thanks for all your help everyone. I can believe I didn't see that I didn't put + and thanks for point out ":" I was so tired and I just wanted to finish I can't believe I wasted all that time getting the math to work just to miss a + and forgot about :
You missed adding + or concatenation after the numerical expressions and : should have been in quotes too as its a string. Better yet use templating, both examples below:
// With concatination
console.log("The volume of the cone " + (10 / 3 * (3.14 * (5 ** 2))) + " is greater than the volume of the cylinder " + (10 * (3.14 * (5 ** 2))) + ": " + (261 > 785));
// With templating
console.log(`The volume of the cone ${(10 / 3 * (3.14 * (5 ** 2)))} is greater than the volume of the cylinder ${(10 * (3.14 * (5 ** 2)))}: ${(261 > 785)}`);
You missed a + and ":"
With template literals
console.log(`The volume of the cone ${(10 / 3 * (3.14 * (5 **2)))} is greater than the volume of the cylinder ${(10 * (3.14 * (5 **2)))} : ${261 > 785}`);
Template literals
It should be one from below
String Concatenation
console.log("The volume of the cone " + (10 / 3 * (3.14 * (5 **2))) + "is greater than the volume of the cylinder " + (10 * (3.14 * (5 **2))) + ":" + (261 > 785));
Please Note the importance of the paranthesis in (261 > 785). Removing the bracket will throw a false as output. Because the string expression in console will be checked against > 785 if the bracket is removed, that will result in false as result
OR
Template Literals
console.log(`The volume of the cone ${(10 / 3 * (3.14 * (5 **2)))} is greater than the volume of the cylinder ${(10 * (3.14 * (5 **2)))} : ${261 > 785}`);
I found some code snippets and I'm not sure what it means:
var flip = Math.floor(Math.random() * (1 - 0 + 1)) + 0;
and
Math.floor(Math.random() * (max - min + 1)) + min
I'm still getting familiar with Javascript... could someone give me a reader's digest condensed version?
Math.floor() Round a number downward to its nearest integer
For example: if you have 2.7 it will round down to 2.
Math.random() Return a random number between 0 and 1
For example: .693
I know there's several questions on this, but I'm struggling to find out how to use Math.random to get random numbers between two high integers?
So, for example, between 50 and 80. I thought this would work...
'left': Math.floor((Math.random() * 80) + 50) + '%'
Any ideas?
Assuming the range is inclusive on both ends:
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
You need to know the range of the random.
Between 50 and 80, the range is 30 (80 - 50 = 30), then you add 1.
Therefor, the random would look like this :
Math.floor(Math.random() * 31) + 50
Here consider your min=50 and max = 80 refer below code:
var number = Math.floor(Math.random() * (max - min) + min);
This will solve your problem. You can try any range by changing min and max.
I have this code in JavaScript:
SolarPanels = parseInt(lRemainingWidth / (panel_width + ( 2 * lPanelInterSpace)));
and then I alert the SolarPanels value which gives NaN as output,
alert("SolarPanels "+SolarPanels);
This 1 line is a tiny part of a huge calculation, but my code seems to fail here,
with the use of alerts i've read out the values of SolarPanels, lRemainingWidth, panel_width and lPanelInterSpace
which are the following:
lRemainingwidth = 17.4.320227272727276
SolarPanels = 0
panel_width = 1.65
lPanelInterSpace = 0.02
I think it has to do with the 2 dots in lRemainingWidth, either way, I don't know how to fix it. Why the lRemainingWidth has 2 dots?
Update :
This is the part that calculates the lRemainingWidth :
if(HalforDouble === "Yes")
{
lRemainingWidth = (roof_ridge /2) + ((lRemainingHeight / Math.tan((lRoofEdgeDegrees * Math.PI) / 180)) - lRoofEdge);
}
else
{
lRemainingWidth = roof_ridge + (2 * ((lRemainingHeight / Math.tan((lRoofEdgeDegrees * Math.PI) / 180)) - lRoofEdge));
}
The values here are:
lRemainingWidth = 0
roof_ridge = 17
lRemainingHeight = 20.769000000000002
lRoofEdgeDegrees = 83.5169263071276
lRoofEdge = 0.2
Your problem is that you mix strings and numbers
Start with this code before any computation :
var roof_ridge = parseFloat(roof_ridge);
There might be other strings hidden in your code but we don't see them. Apply the same conversion on them.
lRemainingWidth = roof_ridge + (2 * ((lRemainingHeight / Math.tan((lRoofEdgeDegrees * Math.PI) / 180)) - lRoofEdge));
If roof_ridge is a string then the + does string concatenation instead of addition.
Change this to
lRemainingWidth = +roof_ridge + (2 * ((lRemainingHeight / Math.tan((lRoofEdgeDegrees * Math.PI) / 180)) - lRoofEdge));
The prefix + operator in +roof_ridge coerces its argument to a number.
It seems like a cornerstone of the issue in roof_ridge variable. This variable is instance of String class, not a number. So, when you code go to this line:
lRemainingWidth = roof_ridge + (2 * ((lRemainingHeight / Math.tan((lRoofEdgeDegrees * Math.PI) / 180)) - lRoofEdge));
the next calculation is done:
'17' + whatever_float_value = got string concatenation instead of number's sum.
To fix this just add:
lRemainingWidth = parseFloat(roof_ridge) + (2 * ((lRemainingHeight / Math.tan((lRoofEdgeDegrees * Math.PI) / 180)) - lRoofEdge));
The Formula looks like this:
(25000 x (.06 / 12)) / (1 - ((1 + (.06 / 12))^(-36))) = 760.548436
I have been attempting to convert this to javascript but with not much luck. If you put that above formula into google you will see the answer.
After many attempts and different methods, braking up the formula into different variables then dividing them, I haven't had any luck, when I came up with this, it got me the wrong answer:
var loan = 25000;
var rate = 6 / 100;
var term = 36;
var calculate = (loan * (rate / 12)) / (1 - ((1 + (rate / 12))^(-term)));
console.log(calculate);
Output was:
3.4722222222222223
And not 760.548436. Anyone have any ideas?
The caret is a bitwise operator. You want this formula instead:
calculate = (loan * (rate / 12)) / (1 - Math.pow(1 + (rate / 12), -term));
It gives you the answer you expect, 760.5484362888927