...

View Full Version : Help With Basic Calculator



Alsark
09-06-2008, 09:51 PM
Alright, so I have this damage calculator: http://www.runescapehall.net/alsark/PoxNora/Damage%20Calculator.html ((Feel free to look at the source code, in fact, I guess you'd have to to help))

Now I have three problems. I need radio buttons with the following options: Normal (100%), 110%, 120%, 125%, 130%, 135%, 140%, 145%, and 150%. This field is "Damage Amplification", and will modify the damage field (not the result field, which has the button next to it)

Second, I need another field (Resistances/Vulnerability) of radio buttons which also modifies the damage field (not the result field), but after Amplification has already modified it. The options would be Normal (100%), 80%, 65%, 50%, and 140%.

For both of these, changing the radio button should not modify what has already been modified, it should modify the original (or for Resistance and Vulnerability, it should always be modifying after Amplification, but it should not be modifying values after other radio buttons have changed the damage field). So I would need it so that switching a radio button would restore the damage field to what it was prior to clicking whatever radio button was clicked (I don't know if this would happen by default in coding, so I just wanted to make sure). So I guess maybe there would be three damage variables, one prior to any modifications, one after amplification, and one after resistances/vulnerabilities (but I'd have no idea how this would work), and each of the two latter steps would always modify from only the step before it.

Last, I need to make it so that the attack field can modify the damage field (after amplification and resistances/vulnerabilites have been applied, so it would modify the last of the three damage step variables) by no more than +40% to get the result field and I need to make it so the defense field can modify the damage field by no more than -80% to get the result field. So in other words, 999999 defense should reduce the damage no more than, say, 200 defense would in most circumstances (they'd both reduce it by 80%).

Even if you can only help me with one of these three parts, any amount of help would be greatly appreciated and you will be credited in both the source and the damage calculator site (assuming you want to be, let me know if you don't). If you have any questions regarding anything, let me know.

Also, as payment (if you can help me with all parts of this topic), if you want, and if you join PoxNora (the game in which this code is based upon), then I will give you one exotic card, two rare cards, seven uncommon cards, and ten common cards, which would give you enough runes to make a deck (a deck is 20 cards). Since it costs real money to buy the cards, I'm more or less offering money for help. (Important note: You can only trade with people if you have at least one card. You can buy a random common for 50 cents in the online store and trade with me that way).

Philip M
09-07-2008, 09:45 AM
You are asking for a considerable amount of work - I think you would be better posting this in the Web Projects section.

Alsark
09-07-2008, 09:01 PM
Hm... understandable. How about just this part, then?


Now I have three problems. I need radio buttons with the following options: Normal (100%), 110%, 120%, 125%, 130%, 135%, 140%, 145%, and 150%. This field is "Damage Amplification", and will modify the damage field (not the result field, which has the button next to it)

With just that code I may be able to figure out myself how the next part works. Well doubtfully, but it will at least put me in the right direction. Because right now, I am *totally* lost. I have the buttons, and I input some math for them, but when I click them, nothing happens :/. As far as I know, my code looks correct, but then again, I don't really know anything about Javascript.

Philip M
09-08-2008, 09:10 AM
Here you are - but please remeber that this forum is not intended as a free coding service for people who on their own admission don't really know anything about Javascript.


<form name= "myform">
<input type = "radio" name= "rad1" value = 100 checked>100&#37;
<input type = "radio" name= "rad1" value = 110>110%
<input type = "radio" name= "rad1" value = 120>120%
<input type = "radio" name= "rad1" value = 125>125%
<input type = "radio" name= "rad1" value = 130>130%
<input type = "radio" name= "rad1" value = 140>140%
<input type = "radio" name= "rad1" value = 145>145%
<input type = "radio" name= "rad1" value = 150>150%
<br><br>
<input type = "button" value = "Adjust Damage" onclick = "chkRadios()">
</form>


<script type = "text/javascript">
function chkRadios() {
for (var i=0; i<document.myform.rad1.length; i++) {
if (document.myform.rad1[i].checked) {
var x = document.myform.rad1[i].value;
x = x/100;
}
}
alert ("Damage Ampflication Value = " + x)
}
</script>

Alsark
09-08-2008, 02:40 PM
Gracias. It doesn't seem to be working, though, unfortunately :(.

http://www.runescapehall.net/alsark/PoxNora/Damage&#37;20Calculator2.html

I spent some time fiddling around with it and trying to dissect it, but alas, to no avail. One thing that stood out to me was this:


var x = document.ampform.rad1[i].value;
x = x/100;
}
}
alert ("Damage Ampflication Value = " + x)

I was wondering why the 'x' variable was being used in a formula to find itself. I tried replacing that with 'y' and then + y down below, but that didn't do anything. I'm sure it's correct as is, though.

(( I changed myform to ampform for all instances ))

The script also doesn't seem to reference "dmge" at all, which I'd think it would need to, but I wouldn't really know. I am going to fiddle around with things some more after classes are over.

The other thing I am trying to code in is actually very similar to this, so once I get this working I think I should be good to go on my own from there.

Thanks!

Philip M
09-08-2008, 05:12 PM
Gracias. It doesn't seem to be working, though, unfortunately :(.


Well, it works for me. It is always somewhat irritating when people who have no idea of what they are talking about blithely announce that something they have been given by an experienced coder does not work. There is another possibility.

When the user selects a radio button the value of that button is alerted. x = x/100 reduces e.g. 125 to 1.25, and presumably the next stage is damage = damage * x (so if damage was initially 400 it would now be 500).

But I am sorry to say that is as far as I am prepared to go.

Alsark
09-08-2008, 11:57 PM
Yeah, I found out what I had done wrong. The code was close enough to what I had meant, and yeah, I had to find a way to multiply that by the damage value. After much trial and error, I was able to get it, as well as add a whole new form using similar code.

This is the end result: http://www.runescapehall.net/alsark/PoxNora/Damage&#37;20Calculator.html

Thanks. I apologize for annoying you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum