Quote
Originally posted by Artanis:
**looks at javascript
:eek:
...I love actionscripting...
consults javascript textbook
Javascript:
function calculate(ship_strength,ship_crew,escort_strength_a,escort_strength_b,escort_strength_c,
escort_strength_d,escort_strength_e,escort_strength_f,escort_crew_a,escort_crew_b,
escort_crew_c,escort_crew_d,escort_crew_e,escort_crew_f,marines_crew,marines_percentage,
target_strength,target_crew){
if(escort_strength_a == ""){escort_strength_a=0}
else{escort_strength_a=eval(escort_strength_a*0.1)};
if(escort_strength_b == ""){escort_strength_b=0}
else{escort_strength_b=eval(escort_strength_b*0.1)};
if(escort_strength_c == ""){escort_strength_c=0}
else{escort_strength_c=eval(escort_strength_c*0.1)};
if(escort_strength_d == ""){escort_strength_d=0}
else{escort_strength_d=eval(escort_strength_d*0.1)};
if(escort_strength_e == ""){escort_strength_e=0}
else{escort_strength_e=eval(escort_strength_e*0.1)};
if(escort_strength_f == ""){escort_strength_f=0}
else{escort_strength_f=eval(escort_strength_f*0.1)};
var escort_strength=eval(escort_strength_a+escort_strength_b+escort_strength_c+escort_strength_d+escort_strength_e+escort_strength_f);
var strength=eval(ship_strength+escort_strength);
if(escort_crew_a == ""){escort_crew_a=0}
else{escort_crew_a=eval(escort_crew_a*0.1)};
if(escort_crew_b == ""){escort_crew_b=0}
else{escort_crew_b=eval(escort_crew_b*0.1)};
if(escort_crew_c == ""){escort_crew_c=0}
else{escort_crew_c=eval(escort_crew_c*0.1)};
if(escort_crew_d == ""){escort_crew_d=0}
else{escort_crew_d=eval(escort_crew_d*0.1)};
if(escort_crew_e == ""){escort_crew_e=0}
else{escort_crew_e=eval(escort_crew_e*0.1)};
if(escort_crew_f == ""){escort_crew_f=0}
else{escort_crew_f=eval(escort_crew_f*0.1)};
var escort_crew=eval(escort_crew_a+escort_crew_b+escort_crew_c+escort_crew_d+escort_crew_e+escort_crew_f);
var crew=eval(marines_crew+escort_crew+ship_crew);
target_crew=eval(target_crew*10);
target_strength=eval(target_strength*5);
var sub_odds=eval(crew/target_strength);
sub_odds=eval(sub_odds*100);
var odds=eval(sub_odds+marines_percentage);
if(strength > target_strength){var odds=eval(odds+10)};
var max_odds=eval(odds+5);
var min_odds=eval(odds-5);
if(max_odds > 75){max_odds=75};
if(min_odds > 75){min_odds=75};
if(max_odds < 0){max_odds=1};
if(min_odds < 0){min_odds=1};
max_odds=max_odds.split(".");
min_odds=min_odds.split(".");
document.res_form.minodds.value=min_odds(0);
document.res_form.maxodds.value=max_odds(0);
So besides the obvious "You're not pasting strings together, you're evaluating mathematic expressions," try that and see if it works.
(edit: broke the tables)
(edit2: fixing stupid mistakes. (of mine.))
(edit3: changed the "/10" to "0.1", which is the same thins, but won't give the "divide by zero" error)*
In JavaScript, if you paste strings together with an
eval()
statement and it forms a mathematical equation, it automatically evaluates it and the sum, difference, product, quotient or combination thereof is stored in the variable. You could indeed say variable a + variable b, but the way it is set up, my form sends up strings, not numbers.
Also, the "division by zero" error won't be a problem. If you check the syntax, it performs that operation if and only if the value is not blank. If it is, it defaults to zero.
But I'll try your modifications anyway, as soon as I get around to it.
------------------
The programmer's code of entomology: there's always another bug.
Microsquash Winblows users: stop asking for plugins. (url="http://"http://www.aznt.com/EVN/EVNEW/")Make one yourself.(/url)