Hi! I hope you are doing fine!
I've been working on some kind of tool for a Mining system for an ARPG. I've managed to make a Random Number Generator with probabilities -I'm using Javascript-.
My idea is to do the following:
In this project, 'Mining' can go from level 0 up to level 10. And as the player levels up, each probability to find minerals goes up +4% for each level (lvl 1: +4%, lvl 2: +8%, lvl 3: +12% ...). I've given numbers to each mineral (5 in total). Each of these ores has this probability of appearing at level 0:
-Mining Lvl 0- 1. Copper: 80% 2. Iron: 60% 3. Titanium: 40% 4. Silver: 10% 5. Platinum: 5% And everytime time a player levels up +4% should be added to each ore.
What I did:
I wanted to create a tool that would give me a random number (from 1 to 5) depending on the probabilities of each one AND the players Level. So what I did was create a page where I would input the level, then click a button and then the result should appear on a < p > element.
The page
<div class="genbox"> <!--this is just a container for the tool-->
<h3><u>Enter Level & Click the button to get a random Number</u></h3>
<label for="txtLvl">Current Level:</label>
<input type="number" id="txtLvl" name="Enter current Lvl here">
<button onclick=mLvl() class="sbutton">Click me!</button>
<br><hr>
<p id="mresult">Result Here</p>
<hr>
</div>
And here's my function:
function mLvl() {
//to get the value entered
//need to check if value=0,1,2,3...10 --
//var inputText = document.getElementById(txtLvl).value;
//For lvl 0:
function mRandom() {
var n=Math.floor(Math.random()*100)
switch(n){
case n<80:
return 1;
case n<60:
return 2;
case n<40:
return 3;
case n<10:
return 4;
case n<5:
return 5;
}
}
document.getElementById("mresult").innerHTML= mRandom();
}
Here I wanted to test if this was working and just click the button to get the result on a < p > element. The problem is that whenever I did, I would get 'undefined' printed out instead.
I would like to know how to fix it so that I can display the value when I click the button.
**Thank you so much for reading, and have a nice day.**