Alsark

08-28-2008, 02:27 AM

Alright, so I am making a kind of "calculator" to determine output damage value for a game called PoxNora. There is a complex formula to determine how much damage a unit will receive by subtracting the attacker's attack by the defender's defense and then... well, it's complicated. Anyway, it's nice to have some kind of calculator to do it for you, which is why I was trying to code one. I can get a basic formula working, like ATK+DMG+DEF=outputDMG, but I cannot get the actual formula working.

Ergo, the problem lies somewhere within this code specifically:

// clears field of default value

function clear_field(field) {

if (field.value==field.value) {

field.value=''

}

}

function Damage0(form)

form.result.value = if((parseInt(form.attack.value) - parseInt(form.defense.value))<1)

{

Math.round((parseInt(form.damage.value)) - (0.02 * (Math.abs(parseInt(form.attack.value) - parseInt(form.defense.value))) * (parseInt(form.damage.value)))

}

else

{

Math.round((parseInt(form.damage.value)) + (0.01 * (parseInt(form.attack.value) - parseInt(form.defense.value)) * (parseInt(form.damage.value)))

};

//-->

The entire code shouldn't be necessary, since the rest of the code works fine with basic formulas. It's just when I try that code, I get an error and it doesn't calculate a thing.

I have ZERO Javascript experience (so I am sure that this is a stupid question). Yes, I tried to research the answer myself, but came up blank.

The layout looks something like this: http://www.runescapehall.net/alsark/PoxNora/test.html

That is a sample formula I have (simple addition), but cannot get my more complex formula working.

Ergo, the problem lies somewhere within this code specifically:

// clears field of default value

function clear_field(field) {

if (field.value==field.value) {

field.value=''

}

}

function Damage0(form)

form.result.value = if((parseInt(form.attack.value) - parseInt(form.defense.value))<1)

{

Math.round((parseInt(form.damage.value)) - (0.02 * (Math.abs(parseInt(form.attack.value) - parseInt(form.defense.value))) * (parseInt(form.damage.value)))

}

else

{

Math.round((parseInt(form.damage.value)) + (0.01 * (parseInt(form.attack.value) - parseInt(form.defense.value)) * (parseInt(form.damage.value)))

};

//-->

The entire code shouldn't be necessary, since the rest of the code works fine with basic formulas. It's just when I try that code, I get an error and it doesn't calculate a thing.

I have ZERO Javascript experience (so I am sure that this is a stupid question). Yes, I tried to research the answer myself, but came up blank.

The layout looks something like this: http://www.runescapehall.net/alsark/PoxNora/test.html

That is a sample formula I have (simple addition), but cannot get my more complex formula working.