View Full Version : Taking in data and ouputting an answer
Antoniohawk
09-22-2002, 06:56 PM
I need help with making a forum. I want to be able to calculate something for a game. I want some1 to enter in their current experience, the needed experience, and the amount of experience they receive per fire they make. Then with that information I want whatever "(needed experience - current experience) / fire_experience" equals to be displayed in an input box. I hope you could understand all of that. If not, please ask me questions.
ConfusedOfLife
09-22-2002, 07:15 PM
Do you want your user to enter whatever he wants?! I mean for example for their experience, you can have several buttons ( like begginer, expert and ... ) to do the job, because it's always better to use some buttons ( of course if it's possilbe ) instead of letting user to enter whatever he wants. Anyway, writing what you want is easy, for example if he enters expert then you do something, but the question is : Will he always enter what you expect?
Antoniohawk
09-22-2002, 07:22 PM
They will be entering in a number. The experience deals in numbers and at a certain number you grow a lvl.
RadarBob
09-22-2002, 09:26 PM
Apologies for belaboring the point, but how your experience levels works of course will have a direct effect on the formula you're asking for. What you're showing seems terribly too simplistic, it seems at first glance. For example If you have have a higher experience level than needed, do you lose points? The calculation you show would result in a negative number in this case.
You'll have to decide how experience grows. I imagine all these experience levels are weighted in a non-linear way. In other words, a success as a beginner at a beginner's level is worth a different amount of points than an expert's earned points at that same level. But a success at any experience level should be worth something.
If you plotted experience vs. points earned on a graph I'd expect to see a curve, not a straight line.
Once you define that points earned curve you can write math stuff to approximate that curve. You will end up with a javascript function that will calculate points earned for any given current experience level & the needed experience level. BTW javascript is not up to the task of making it very sophisticated. Simulating "real life" things well gets into some heady math. Nonetheless you can come up with something reasonable - but it must be more "realistic" than the simple subtraction calculation you show.
Antoniohawk
09-23-2002, 02:29 AM
LOL :D This is alot simpler than u guys are making it. Here is the code for a form:
____________________________________________________
<form name ="form">
<input name="number1">//a person enters a # in here
<br>
<input name="number2">//a person enters a # in here
<br>
<input name="number3">//a person enters a # in here
<br>
<input type="button" value="Submit">//the info is submitted and put in the equation "(number1 - number2) / number3
<br>
<input name="output">//the answer to the equation is outputted here
</form>
____________________________________________________
Thats all i want. I want the answer to the equation outputted in the last input box. you guys help me with that and i figure out the rest.
glenngv
09-23-2002, 06:37 AM
<script language=javascript>
function calc(f){
var num1 = f.number1.value;
var num2 = f.number2.value;
var num3 = f.number3.value;
if (isNaN(num1)){
alert("Number 1 must be numeric.");
f.number1.focus();
return;
}
else if (isNaN(num2)){
alert("Number 2 must be numeric.");
f.number2.focus();
return;
}
else if (isNaN(num3)){
alert("Number 3 must be numeric.");
f.number3.focus();
return;
}
else if (num3=="0"){
alert("Number 3 must not be zero.");
f.number3.focus();
return;
}
f.output.value = (num1-num2)/num3;
}
</script>
and you will call it like this:
<input type="button" value="Submit" onclick="calc(this.form)">
just a little note, don't name your form as form, it is a reserved word in JavaScript.
Antoniohawk
09-23-2002, 09:32 PM
Thx alot glenn i will try that out. you even put in some stuff that i didnt need like the alerts, but it makes it all the better lol. Thx again!:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.